From 516fe408b90e702b8452dddcb9a8e27b1b5ab9d3 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Mon, 26 Jun 2023 16:40:27 +0800 Subject: [PATCH] fix(association-field):submitting failed after adding data in subform for multiple association fields (#2065) * fix: toManay sub-form add new data misalignment * fix: toManay sub-form add new submit failed * refactor: code improve * refactor: code improve --- packages/core/client/src/block-provider/hooks/index.ts | 2 +- .../schema-component/antd/association-field/Editable.tsx | 3 +-- .../schema-component/antd/association-field/Nester.tsx | 9 ++++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/core/client/src/block-provider/hooks/index.ts b/packages/core/client/src/block-provider/hooks/index.ts index fc2d4ee38..d970a7bad 100644 --- a/packages/core/client/src/block-provider/hooks/index.ts +++ b/packages/core/client/src/block-provider/hooks/index.ts @@ -175,7 +175,7 @@ export const useCreateActionProps = () => { ...overwriteValues, ...assignedValues, }, - filterKeys:filterKeys, + filterKeys: filterKeys, }); actionField.data.loading = false; actionField.data.data = data; diff --git a/packages/core/client/src/schema-component/antd/association-field/Editable.tsx b/packages/core/client/src/schema-component/antd/association-field/Editable.tsx index 319811852..fce5c5e5e 100644 --- a/packages/core/client/src/schema-component/antd/association-field/Editable.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/Editable.tsx @@ -1,5 +1,5 @@ import { Field } from '@formily/core'; -import { observer, useField, useFieldSchema, useForm } from '@formily/react'; +import { observer, useField, useForm } from '@formily/react'; import React from 'react'; import { SchemaComponentOptions } from '../../'; import { useAssociationCreateActionProps as useCAP } from '../../../block-provider/hooks'; @@ -17,7 +17,6 @@ const EditableAssociationField = observer( const { multiple } = props; const field: Field = useField(); const form = useForm(); - const fieldSchema = useFieldSchema(); const { options: collectionField, currentMode } = useAssociationFieldContext(); const useCreateActionProps = () => { diff --git a/packages/core/client/src/schema-component/antd/association-field/Nester.tsx b/packages/core/client/src/schema-component/antd/association-field/Nester.tsx index 6e912d219..19096f4a0 100644 --- a/packages/core/client/src/schema-component/antd/association-field/Nester.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/Nester.tsx @@ -2,8 +2,9 @@ import { CloseOutlined, PlusOutlined } from '@ant-design/icons'; import { css } from '@emotion/css'; import { ArrayField } from '@formily/core'; import { spliceArrayState } from '@formily/core/esm/shared/internals'; -import { RecursionField, observer, useFieldSchema } from '@formily/react'; +import { observer, RecursionField, useFieldSchema } from '@formily/react'; import { action } from '@formily/reactive'; +import { each } from '@formily/shared'; import { Button, Card, Divider, Tooltip } from 'antd'; import React, { useContext } from 'react'; import { useTranslation } from 'react-i18next'; @@ -62,6 +63,12 @@ const ToManyNester = observer( insertCount: 1, }); field.value.splice(index + 1, 0, {}); + + each(field.form.fields, (field, key) => { + if (!field) { + delete field.form.fields[key]; + } + }); return field.onInput(field.value); }); }}