/
modal-form-reset.tsx
102 lines (97 loc) · 2.71 KB
/
modal-form-reset.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import type { ProFormInstance } from '@ant-design/pro-components';
import { ModalForm, ProFormText } from '@ant-design/pro-components';
import { Button, message, Space } from 'antd';
import { useRef, useState } from 'react';
const waitTime = (time: number = 100) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, time);
});
};
export default () => {
const restFormRef = useRef<ProFormInstance>();
const formRef = useRef<ProFormInstance>();
const [modalVisible, setModalVisible] = useState<boolean>(false);
return (
<Space>
<ModalForm
title="新建表单"
formRef={restFormRef}
open={modalVisible}
trigger={
<Button
type="primary"
onClick={() => {
setModalVisible(true);
}}
>
通过 formRef 重置
</Button>
}
onVisibleChange={setModalVisible}
submitter={{
searchConfig: {
resetText: '重置',
},
resetButtonProps: {
onClick: () => {
restFormRef.current?.resetFields();
// setModalVisible(false);
},
},
}}
onFinish={async (values) => {
await waitTime(2000);
console.log(values);
message.success('提交成功');
return true;
}}
>
<ProFormText
width="md"
name="name"
label="签约客户名称"
tooltip="最长为 24 位"
placeholder="请输入名称"
/>
<ProFormText width="md" name="company" label="我方公司名称" placeholder="请输入名称" />
</ModalForm>
<ModalForm
title="新建表单"
formRef={formRef}
trigger={<Button type="primary">通过自定义 footer 按钮重置</Button>}
submitter={{
render: (props, defaultDoms) => {
return [
...defaultDoms,
<Button
key="extra-reset"
onClick={() => {
props.reset();
}}
>
重置
</Button>,
];
},
}}
onFinish={async (values) => {
await waitTime(2000);
console.log(values);
message.success('提交成功');
return true;
}}
>
<ProFormText
width="md"
name="name"
label="签约客户名称"
tooltip="最长为 24 位"
placeholder="请输入名称"
/>
<ProFormText width="md" name="company" label="我方公司名称" placeholder="请输入名称" />
</ModalForm>
</Space>
);
};