From ea136ab6bcd2b1cf345d7a8ccaf2a4fa598a2364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=9B=A8=E6=B0=B4=E8=BF=87=E6=BB=A4=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E6=B0=94-Rain?= <958414905@qq.com> Date: Wed, 22 Nov 2023 17:22:09 +0800 Subject: [PATCH] fix: subform disappears (#3073) --- .../hooks/useLazyLoadDisplayAssociationFieldsOfForm.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/form-item/hooks/useLazyLoadDisplayAssociationFieldsOfForm.ts b/packages/core/client/src/schema-component/antd/form-item/hooks/useLazyLoadDisplayAssociationFieldsOfForm.ts index 9a49b5e6f..7ac6a0d0f 100644 --- a/packages/core/client/src/schema-component/antd/form-item/hooks/useLazyLoadDisplayAssociationFieldsOfForm.ts +++ b/packages/core/client/src/schema-component/antd/form-item/hooks/useLazyLoadDisplayAssociationFieldsOfForm.ts @@ -27,7 +27,7 @@ const useLazyLoadDisplayAssociationFieldsOfForm = () => { const { isInSubForm, isInSubTable } = useFlag() || {}; const schemaName = fieldSchema.name.toString(); - const formValue = isInSubForm || isInSubTable ? subFormValue : form.values; + const formValue = _.cloneDeep(isInSubForm || isInSubTable ? subFormValue : form.values); const collectionFieldRef = useRef(null); if (collectionFieldRef.current == null) { @@ -66,7 +66,13 @@ const useLazyLoadDisplayAssociationFieldsOfForm = () => { .parseVariable(variableString, formVariable) .then((value) => { nextTick(() => { - field.value = transformVariableValue(value, { targetCollectionField: collectionFieldRef.current }); + const result = transformVariableValue(value, { targetCollectionField: collectionFieldRef.current }); + // fix https://nocobase.height.app/T-2608 + if (_.isEmpty(result)) { + field.value = null; + } else { + field.value = result; + } }); }) .catch((err) => {