From ffcf1d9cf1c20086f8a5e56b79e190865b5f4819 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Mon, 3 Apr 2023 10:22:50 +0800 Subject: [PATCH] fix: linkage rule config closing rules require reopening the form to take effect (#1640) --- .../schema-component/antd/form-v2/Form.tsx | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/form-v2/Form.tsx b/packages/core/client/src/schema-component/antd/form-v2/Form.tsx index 2acdd3e87..650fa2c64 100644 --- a/packages/core/client/src/schema-component/antd/form-v2/Form.tsx +++ b/packages/core/client/src/schema-component/antd/form-v2/Form.tsx @@ -114,31 +114,36 @@ const WithForm = (props) => { }; }, []); useEffect(() => { - const id = uid(); - form.addEffects(id, () => { + if (linkageRules.length > 0) { + const id = uid(); const linkagefields = []; - return linkageRules.map((v, index) => { - return v.actions?.map((h) => { - if (h.targetFields) { - const fields = h.targetFields.join(','); - return onFieldReact(`*(${fields})`, (field: any, form) => { - linkagefields.push(field); - linkageMergeAction(h, field, v.condition, form?.values); - if (index === linkageRules.length - 1) { - setTimeout(() => - linkagefields.map((v) => { - v.linkageProperty = {}; - }), - ); - } - }); - } + const formGraph = form.getFormGraph(); + form.addEffects(id, () => { + return linkageRules.map((v, index) => { + return v.actions?.map((h) => { + if (h.targetFields) { + const fields = h.targetFields.join(','); + return onFieldReact(`*(${fields})`, (field: any, form) => { + linkagefields.push(field); + linkageMergeAction(h, field, v.condition, form?.values); + if (index === linkageRules.length - 1) { + setTimeout(() => + linkagefields.map((v) => { + v.linkageProperty = {}; + }), + ); + } + }); + } + }); }); }); - }); - return () => { - form.removeEffects(id); - }; + return () => { + form.removeEffects(id); + form.clearFormGraph(); + form.setFormGraph(formGraph); + }; + } }, [linkageRules]); return fieldSchema['x-decorator'] === 'Form' ? : ; };