-
-
Notifications
You must be signed in to change notification settings - Fork 279
Expand file tree
/
Copy pathbasic.tsx
More file actions
51 lines (45 loc) · 1.17 KB
/
basic.tsx
File metadata and controls
51 lines (45 loc) · 1.17 KB
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
import Form, { Field } from 'rc-field-form';
import React from 'react';
import Input from './components/Input';
type FormData = {
name?: string;
password?: string;
password2?: string;
};
export default () => {
const [form] = Form.useForm<FormData>();
return (
<Form
form={form}
preserve={false}
onFieldsChange={fields => {
console.error('fields:', fields);
}}
>
<Field<FormData> name="name">
<Input placeholder="Username" />
</Field>
<Field<FormData> dependencies={['name']}>
{() => {
return form.getFieldValue('name') === '1' ? (
<Field name="password">
<Input placeholder="Password" />
</Field>
) : null;
}}
</Field>
<Field dependencies={['password']}>
{() => {
const password = form.getFieldValue('password');
console.log('>>>', password);
return password ? (
<Field<FormData> name={['password2']}>
<Input placeholder="Password 2" />
</Field>
) : null;
}}
</Field>
<button type="submit">Submit</button>
</Form>
);
};