Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/components/form/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -460,7 +460,7 @@ const FormItem = forwardRef<FormItemInstance, FormItemProps>((originalProps, ref
value: formValue,
initialData,
isFormList: false,
getValue: () => valueRef.current,
getValue: () => cloneDeep(valueRef.current),
setValue: (newVal: any) => updateFormValue(newVal, true, true),
setField,
validate,
Expand Down
12 changes: 6 additions & 6 deletions packages/components/form/FormList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ const FormList: React.FC<TdFormListProps> = (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),
Expand All @@ -118,11 +118,11 @@ const FormList: React.FC<TdFormListProps> = (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(() => {
Expand Down Expand Up @@ -152,7 +152,7 @@ const FormList: React.FC<TdFormListProps> = (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) =>
Expand Down
Loading