fix(association-field): form.get & set valuesIn field.path (#1972)
* fix: useCreateActionProps * refactor: code improve * fix: form.getValuesIn(field.path) --------- Co-authored-by: katherinehhh <katherine_15995@163.com>
This commit is contained in:
parent
7e30b046d9
commit
295faf569d
@ -1,3 +1,4 @@
|
|||||||
|
import { Field } from '@formily/core';
|
||||||
import { observer, useField, useFieldSchema, useForm } from '@formily/react';
|
import { observer, useField, useFieldSchema, useForm } from '@formily/react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { SchemaComponentOptions } from '../../';
|
import { SchemaComponentOptions } from '../../';
|
||||||
@ -13,7 +14,7 @@ import { useAssociationFieldContext } from './hooks';
|
|||||||
|
|
||||||
const EditableAssociationField = observer((props: any) => {
|
const EditableAssociationField = observer((props: any) => {
|
||||||
const { multiple } = props;
|
const { multiple } = props;
|
||||||
const field: any = useField();
|
const field: Field = useField();
|
||||||
const form = useForm();
|
const form = useForm();
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const { options: collectionField, currentMode } = useAssociationFieldContext();
|
const { options: collectionField, currentMode } = useAssociationFieldContext();
|
||||||
@ -27,22 +28,13 @@ const EditableAssociationField = observer((props: any) => {
|
|||||||
const { data } = actionField.data?.data?.data || {};
|
const { data } = actionField.data?.data?.data || {};
|
||||||
if (data) {
|
if (data) {
|
||||||
if (['m2m', 'o2m'].includes(collectionField?.interface) && multiple !== false) {
|
if (['m2m', 'o2m'].includes(collectionField?.interface) && multiple !== false) {
|
||||||
const values = JSON.parse(JSON.stringify(form.values[fieldSchema.name] || []));
|
const values = form.getValuesIn(field.path) || [];
|
||||||
values.push({
|
values.push(data);
|
||||||
...data,
|
form.setValuesIn(field.path, values);
|
||||||
});
|
field.onInput(values);
|
||||||
setTimeout(() => {
|
|
||||||
form.setValuesIn(field.props.name, values);
|
|
||||||
field.onInput(values)
|
|
||||||
}, 100);
|
|
||||||
} else {
|
} else {
|
||||||
const value = {
|
form.setValuesIn(field.path, data);
|
||||||
...data,
|
field.onInput(data);
|
||||||
};
|
|
||||||
setTimeout(() => {
|
|
||||||
form.setValuesIn(field.props.name, value);
|
|
||||||
field.onInput(value)
|
|
||||||
}, 100);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user