Skip to content

Commit

Permalink
fix(Form): fixed setFieldsValue is invalid when ^Cme type is array
Browse files Browse the repository at this point in the history
  • Loading branch information
l123wx committed Dec 12, 2024
1 parent 2743745 commit 86774d7
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/form/hooks/useInstance.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import isEmpty from 'lodash/isEmpty';
import isFunction from 'lodash/isFunction';
import isEqual from 'lodash/isEqual';
import merge from 'lodash/merge';
import get from 'lodash/get';
import set from 'lodash/set';
Expand Down Expand Up @@ -155,7 +156,20 @@ export default function useInstance(

nameLists.forEach((nameList) => {
const fieldValue = get(fields, nameList);
const formItemRef = formMapRef.current.get(nameList.length > 1 ? nameList : nameList[0]);

let formItemRef;
if (nameList.length > 1) {
// 如果是数组,由于内存地址不一致,不能直接使用 Map.get 获取到 formItemRef
for (const [mapNameList, _formItemRef] of formMapRef.current.entries()) {
if (isEqual(nameList, mapNameList)) {
formItemRef = _formItemRef;
break;
}
}
} else {
formItemRef = formMapRef.current.get(nameList[0]);
}

if (formItemRef?.current) {
formItemRef?.current?.setValue?.(fieldValue, fields);
} else {
Expand Down

0 comments on commit 86774d7

Please sign in to comment.