Skip to content

Commit edc85ac

Browse files
committed
fix: form onValues second params values
close ant-design/ant-design#41053
1 parent cbc2bc6 commit edc85ac

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/Field.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type {
1818
RuleError,
1919
} from './interface';
2020
import FieldContext, { HOOK_MARK } from './FieldContext';
21+
import ListContext from './ListContext';
2122
import { toArray } from './utils/typeUtil';
2223
import { validateRules } from './utils/validateUtil';
2324
import {
@@ -625,14 +626,18 @@ class Field extends React.Component<InternalFieldProps, FieldState> implements F
625626

626627
function WrapperField<Values = any>({ name, ...restProps }: FieldProps<Values>) {
627628
const fieldContext = React.useContext(FieldContext);
628-
629+
const listContext = React.useContext(ListContext);
629630
const namePath = name !== undefined ? getNamePath(name) : undefined;
630631

631632
let key: string = 'keep';
632633
if (!restProps.isListField) {
633634
key = `_${(namePath || []).join('_')}`;
634635
}
635636

637+
if (restProps.isListField === undefined && !restProps.isList && listContext) {
638+
restProps.isListField = listContext.inList;
639+
}
640+
636641
// Warning if it's a directly list field.
637642
// We can still support multiple level field preserve.
638643
if (

src/List.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const List: React.FunctionComponent<ListProps> = ({
6060
const pathName = namePath[len];
6161
return [keyManager.keys[pathName], namePath.slice(len + 1)];
6262
},
63+
inList: true,
6364
}),
6465
[prefixName],
6566
);

src/ListContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { InternalNamePath } from './interface';
33

44
export interface ListContextProps {
55
getKey: (namePath: InternalNamePath) => [React.Key, InternalNamePath];
6+
inList: boolean;
67
}
78

89
const ListContext = React.createContext<ListContextProps | null>(null);

0 commit comments

Comments
 (0)