()
| 4 | import { FormRefApi } from "./Form/Form"; |
| 5 | |
| 6 | const Basic: React.FC = () => { |
| 7 | const onFinish = (values: any) => { |
| 8 | console.log('Success:', values); |
| 9 | }; |
| 10 | |
| 11 | const onFinishFailed = (errorInfo: any) => { |
| 12 | console.log('Failed:', errorInfo); |
| 13 | }; |
| 14 | |
| 15 | const form = useRef<FormRefApi>(null); |
| 16 | |
| 17 | return ( |
| 18 | <> |
| 19 | <Button type="primary" onClick={() => { |
| 20 | console.log(form.current?.getFieldsValue()) |
| 21 | }}>打印表单值</Button> |
| 22 | |
| 23 | <Button type="primary" onClick={() => { |
| 24 | form.current?.setFieldsValue({ |
| 25 | username: '东东东' |
| 26 | }) |
| 27 | }}>设置表单值</Button> |
| 28 | |
| 29 | <Form |
| 30 | ref={form} |
| 31 | initialValues={{ remember: true, username: '神说要有光' }} |
| 32 | onFinish={onFinish} |
| 33 | onFinishFailed={onFinishFailed} |
| 34 | > |
| 35 | <Form.Item |
| 36 | label="Username" |
| 37 | name="username" |
| 38 | rules={[ |
| 39 | { required: true, message: '请输入用户名!' }, |
| 40 | { max: 6, message: '长度不能大于 6' } |
| 41 | ]} |
| 42 | > |
| 43 | <Input /> |
| 44 | </Form.Item> |
| 45 | |
| 46 | <Form.Item |
| 47 | label="Password" |
| 48 | name="password" |
| 49 | rules={[{ required: true, message: '请输入密码!' }]} |
| 50 | > |
| 51 | <Input.TextArea /> |
| 52 | </Form.Item> |
| 53 | |
| 54 | <Form.Item name="remember" valuePropName="checked"> |
| 55 | <Checkbox>记住我</Checkbox> |
| 56 | </Form.Item> |
| 57 | |
| 58 | <Form.Item> |
| 59 | <div> |
| 60 | <Button type="primary" htmlType="submit" > |
| 61 | 登录 |
| 62 | </Button> |
| 63 | </div> |
nothing calls this directly
no outgoing calls
no test coverage detected