Skip to content

Commit

Permalink
fix(form): Fixed a bug with nested FormList
Browse files Browse the repository at this point in the history
close #5997
  • Loading branch information
chenshuai2144 committed Oct 14, 2022
1 parent 2235842 commit 2100074
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/field/src/components/Digit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const FieldDigit: ProFieldFC<FieldDigitProps> = (
val = val?.toFixed?.(fieldProps.precision ?? 0);
val = Number(val);
}
return fieldProps?.onChange(val);
return fieldProps?.onChange?.(val);
},
[fieldProps],
);
Expand Down
17 changes: 8 additions & 9 deletions packages/form/src/components/List/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,12 @@ const ProFormListItem: React.FC<
className={`${prefixCls}-action-icon action-copy ${hashId}`}
onClick={async () => {
setLoadingCopy(true);
await action.add(
formInstance?.getFieldValue(
[listContext.listName, rest.name, field.name]
.filter((item) => item !== undefined)
.flat(1),
),
const row = formInstance?.getFieldValue(
[listContext.listName, originName, field.name]
.filter((item) => item !== undefined)
.flat(1),
);
await action.add(row);
setLoadingCopy(false);
}}
/>
Expand All @@ -371,11 +370,11 @@ const ProFormListItem: React.FC<
loadingCopy,
prefixCls,
hashId,
action,
formInstance,
listContext.listName,
rest.name,
field.name,
originName,
action,
]);

const deleteIcon = useMemo(() => {
Expand Down Expand Up @@ -414,7 +413,7 @@ const ProFormListItem: React.FC<
field,
index,
record: formInstance?.getFieldValue?.(
[listContext.listName, rest.name, field.name].filter((item) => item !== undefined).flat(1),
[listContext.listName, originName, field.name].filter((item) => item !== undefined).flat(1),
),
fields,
operation: action,
Expand Down
12 changes: 11 additions & 1 deletion packages/form/src/components/ModalForm/demos/drawer-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ export default () => {
tooltip="最长为 24 位"
placeholder="请输入名称"
/>
<ProFormText width="md" name="company" label="我方公司名称" placeholder="请输入名称" />
<ProFormText
rules={[
{
required: true,
},
]}
width="md"
name="company"
label="我方公司名称"
placeholder="请输入名称"
/>
</ProForm.Group>
<ProForm.Group>
<ProFormText width="md" name="contract" label="合同名称" placeholder="请输入名称" />
Expand Down

0 comments on commit 2100074

Please sign in to comment.