Skip to content

Commit

Permalink
fix: 修复表单数据回填异常
Browse files Browse the repository at this point in the history
  • Loading branch information
lingting committed Aug 2, 2022
1 parent b622a9b commit 3dfcc4a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
16 changes: 9 additions & 7 deletions src/components/Form/FullForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useRef, useImperativeHandle } from 'react';
import { useImperativeHandle, useRef, useState } from 'react';
import type { FormStatus } from './typings';
import type { ProFormInstance } from '@ant-design/pro-form';
import ProForm from '@ant-design/pro-form';
Expand Down Expand Up @@ -43,14 +43,16 @@ const FullForm = <E, P = E>(props: FullFormProps<E, P>) => {
setTitle(undefined);
return;
}
// 清空数据
formRef.current?.resetFields();
// 如果需要回填数据
if (data !== undefined && data !== null) {
formRef.current?.setFieldsValue(data);
}
setTitle(`${defautlTitle[st]}${titleSuffix}`);
setHidden(false);
setTimeout(() => {
// 清空数据
formRef.current?.resetFields();
// 如果需要回填数据
if (data !== undefined && data !== null) {
formRef.current?.setFieldsValue(data);
}
});
};

const submit = async (
Expand Down
18 changes: 10 additions & 8 deletions src/components/Form/ModalForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useRef, useImperativeHandle } from 'react';
import type { ModalFormProps, FormStatus } from './typings';
import { useImperativeHandle, useRef, useState } from 'react';
import type { FormStatus, ModalFormProps } from './typings';
import type { ProFormInstance } from '@ant-design/pro-form';
import { ModalForm as AntdModalForm } from '@ant-design/pro-form';
import type { R } from '@/typings';
Expand Down Expand Up @@ -58,14 +58,16 @@ const ModalForm = <E, P = E>(props: ModalFormProps<E, P>) => {
setModalTitle(undefined);
return;
}
// 清空数据
formRef.current?.resetFields();
// 如果需要回填数据
if (data !== undefined && data !== null) {
formRef.current?.setFieldsValue(data);
}
setModalTitle(`${defautlTitle[st]}${titleSuffix}`);
setVisible(true);
setTimeout(() => {
// 清空数据
formRef.current?.resetFields();
// 如果需要回填数据
if (data !== undefined && data !== null) {
formRef.current?.setFieldsValue(data);
}
});
};

useImperativeHandle(currencyRef, () => ({
Expand Down

0 comments on commit 3dfcc4a

Please sign in to comment.