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
This commit is contained in:
katherinehhh 2023-06-26 16:40:27 +08:00 committed by GitHub
parent 88d4af14df
commit 516fe408b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

View File

@ -175,7 +175,7 @@ export const useCreateActionProps = () => {
...overwriteValues,
...assignedValues,
},
filterKeys:filterKeys,
filterKeys: filterKeys,
});
actionField.data.loading = false;
actionField.data.data = data;

View File

@ -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 = () => {

View File

@ -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);
});
}}