2019-07-03 20:14:39 +08:00
|
|
|
---
|
|
|
|
order: 0
|
|
|
|
title:
|
|
|
|
zh-CN: 基本使用
|
|
|
|
en-US: Basic Usage
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
基本的表单数据域控制展示,包含布局、初始化、验证、提交。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Basic Form data control. Includes layout, initial values, validation and submit.
|
|
|
|
|
|
|
|
```tsx
|
|
|
|
import { Form, Input, Button, Checkbox } from 'antd';
|
|
|
|
|
|
|
|
const Demo = () => {
|
2020-12-17 15:09:18 +08:00
|
|
|
const onFinish = (values: any) => {
|
2019-07-03 20:14:39 +08:00
|
|
|
console.log('Success:', values);
|
|
|
|
};
|
|
|
|
|
2020-12-17 15:09:18 +08:00
|
|
|
const onFinishFailed = (errorInfo: any) => {
|
2019-07-03 20:14:39 +08:00
|
|
|
console.log('Failed:', errorInfo);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form
|
|
|
|
name="basic"
|
2021-06-16 13:05:55 +08:00
|
|
|
labelCol={{ span: 8 }}
|
|
|
|
wrapperCol={{ span: 16 }}
|
2019-07-03 20:14:39 +08:00
|
|
|
initialValues={{ remember: true }}
|
|
|
|
onFinish={onFinish}
|
|
|
|
onFinishFailed={onFinishFailed}
|
2021-06-04 14:44:41 +08:00
|
|
|
autoComplete="off"
|
2019-07-03 20:14:39 +08:00
|
|
|
>
|
2019-12-29 18:32:13 +08:00
|
|
|
<Form.Item
|
|
|
|
label="Username"
|
|
|
|
name="username"
|
|
|
|
rules={[{ required: true, message: 'Please input your username!' }]}
|
|
|
|
>
|
2019-07-03 20:14:39 +08:00
|
|
|
<Input />
|
|
|
|
</Form.Item>
|
|
|
|
|
2019-12-29 18:32:13 +08:00
|
|
|
<Form.Item
|
|
|
|
label="Password"
|
|
|
|
name="password"
|
|
|
|
rules={[{ required: true, message: 'Please input your password!' }]}
|
|
|
|
>
|
2019-07-03 20:14:39 +08:00
|
|
|
<Input.Password />
|
|
|
|
</Form.Item>
|
|
|
|
|
2021-06-16 13:05:55 +08:00
|
|
|
<Form.Item name="remember" valuePropName="checked" wrapperCol={{ offset: 8, span: 16 }}>
|
2019-07-03 20:14:39 +08:00
|
|
|
<Checkbox>Remember me</Checkbox>
|
|
|
|
</Form.Item>
|
|
|
|
|
2021-06-16 13:05:55 +08:00
|
|
|
<Form.Item wrapperCol={{ offset: 8, span: 16 }}>
|
2019-07-03 20:14:39 +08:00
|
|
|
<Button type="primary" htmlType="submit">
|
|
|
|
Submit
|
|
|
|
</Button>
|
|
|
|
</Form.Item>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-04-15 16:20:56 +08:00
|
|
|
export default Demo;
|
2019-07-03 20:14:39 +08:00
|
|
|
```
|