diff --git a/packages/components/form/FormItem.tsx b/packages/components/form/FormItem.tsx index c6485514e1..de65c8ed2b 100644 --- a/packages/components/form/FormItem.tsx +++ b/packages/components/form/FormItem.tsx @@ -4,7 +4,7 @@ import { CloseCircleFilledIcon as TdCloseCircleFilledIcon, ErrorCircleFilledIcon as TdErrorCircleFilledIcon, } from 'tdesign-icons-react'; -import { get, isEqual, isFunction, isObject, isString, set } from 'lodash-es'; +import { cloneDeep, get, isEqual, isFunction, isObject, isString, set } from 'lodash-es'; import useConfig from '../hooks/useConfig'; import useDefaultProps from '../hooks/useDefaultProps'; @@ -460,7 +460,7 @@ const FormItem = forwardRef((originalProps, ref value: formValue, initialData, isFormList: false, - getValue: () => valueRef.current, + getValue: () => cloneDeep(valueRef.current), setValue: (newVal: any) => updateFormValue(newVal, true, true), setField, validate, diff --git a/packages/components/form/FormList.tsx b/packages/components/form/FormList.tsx index 61b58c1f9c..0c5f383193 100644 --- a/packages/components/form/FormList.tsx +++ b/packages/components/form/FormList.tsx @@ -102,11 +102,11 @@ const FormList: React.FC = (props) => { function setListFields(fieldData: any[], callback: Function) { if (isEqual(formListValue, fieldData)) return; - - const newFields = fieldData.map((_, index) => { + const newFieldData = [...fieldData]; + const newFields = newFieldData.map((_, index) => { const currField = fields[index]; const oldItem = formListValue[index]; - const newItem = fieldData[index]; + const newItem = newFieldData[index]; const noChange = currField && isEqual(oldItem, newItem); return { key: noChange ? currField.key : (globalKey += 1), @@ -118,11 +118,11 @@ const FormList: React.FC = (props) => { Array.from(formListMapRef.current.values()).forEach((formItemRef) => { if (!formItemRef.current) return; const { name: childName } = formItemRef.current; - const data = get(fieldData, childName); + const data = get(newFieldData, childName); if (data !== undefined) callback(formItemRef, data); }); - updateFormList(newFields, fieldData); + updateFormList(newFields, newFieldData); } useEffect(() => { @@ -152,7 +152,7 @@ const FormList: React.FC = (props) => { initialData, isFormList: true, formListMapRef, - getValue: () => get(form?.store, fullPath), + getValue: () => cloneDeep(get(form?.store, fullPath)), validate: (trigger = 'all') => { const resultList = []; const validates = [...formListMapRef.current.values()].map((formItemRef) =>