mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-03 16:39:41 +08:00
55e0d13234
* chore: Add demo tsx check * chore: Prettier * chore: Fix lint * fix: Upload ts definition * chore: Demo onlt * docs: Fix demo * chore: Add CI action * chore: Use real name * chore: fix ts define * chore: fix more ts * chore: fix more ts * chore: More ts * chore: More ts * chore: More ts * chore: More ts * chore: More ts * chore: More ts * chore: More ts * chore: Update all rest TS demo * fix test case
75 lines
1.5 KiB
Markdown
75 lines
1.5 KiB
Markdown
---
|
|
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 layout = {
|
|
labelCol: { span: 8 },
|
|
wrapperCol: { span: 16 },
|
|
};
|
|
const tailLayout = {
|
|
wrapperCol: { offset: 8, span: 16 },
|
|
};
|
|
|
|
const Demo = () => {
|
|
const onFinish = (values: any) => {
|
|
console.log('Success:', values);
|
|
};
|
|
|
|
const onFinishFailed = (errorInfo: any) => {
|
|
console.log('Failed:', errorInfo);
|
|
};
|
|
|
|
return (
|
|
<Form
|
|
{...layout}
|
|
name="basic"
|
|
initialValues={{ remember: true }}
|
|
onFinish={onFinish}
|
|
onFinishFailed={onFinishFailed}
|
|
>
|
|
<Form.Item
|
|
label="Username"
|
|
name="username"
|
|
rules={[{ required: true, message: 'Please input your username!' }]}
|
|
>
|
|
<Input />
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
label="Password"
|
|
name="password"
|
|
rules={[{ required: true, message: 'Please input your password!' }]}
|
|
>
|
|
<Input.Password />
|
|
</Form.Item>
|
|
|
|
<Form.Item {...tailLayout} name="remember" valuePropName="checked">
|
|
<Checkbox>Remember me</Checkbox>
|
|
</Form.Item>
|
|
|
|
<Form.Item {...tailLayout}>
|
|
<Button type="primary" htmlType="submit">
|
|
Submit
|
|
</Button>
|
|
</Form.Item>
|
|
</Form>
|
|
);
|
|
};
|
|
|
|
ReactDOM.render(<Demo />, mountNode);
|
|
```
|