ant-design/components/form/demo/validate-static.md

113 lines
2.7 KiB
Markdown
Raw Normal View History

2016-03-31 09:40:55 +08:00
---
order: 10
title:
2016-07-31 09:53:51 +08:00
zh-CN: 校验提示
en-US: Validation message
2016-03-31 09:40:55 +08:00
---
2015-06-15 20:24:01 +08:00
2016-07-31 09:53:51 +08:00
## zh-CN
2015-10-29 08:41:51 +08:00
我们为表单控件定义了三种校验状态,为 `<FormItem>` 定义 `validateStatus` 属性即可。
2015-06-15 20:24:01 +08:00
2016-04-08 09:33:09 +08:00
validateStatus: 'success', 'warning', 'error', 'validating'。
2015-06-15 20:24:01 +08:00
另外为输入框添加反馈图标,设置 `<FormItem>``hasFeedback` 属性值为 `true` 即可。
2015-07-07 11:25:16 +08:00
2016-07-31 09:53:51 +08:00
## en-US
We provide three kinds of validation status for form. You can use it just define `validateStatus` property on `<FormItem>`.
validateStatus: 'success', 'warning', 'error', 'validating'。
To set `hasFeedback` property to `true` enable to display feed icon of input control.
2017-01-19 15:19:03 +08:00
````__react
import { Form, Input, DatePicker, Col } from 'antd';
2015-10-29 08:41:51 +08:00
const FormItem = Form.Item;
2015-06-15 20:24:01 +08:00
2015-10-25 11:35:03 +08:00
ReactDOM.render(
2017-01-05 16:57:41 +08:00
<Form>
2015-10-29 08:41:51 +08:00
<FormItem
2016-07-31 09:53:51 +08:00
label="Fail"
labelCol={{ span: 5 }}
wrapperCol={{ span: 12 }}
2015-10-29 08:41:51 +08:00
validateStatus="error"
2016-09-22 10:09:22 +08:00
help="Should be combination of numbers & alphabets"
>
2016-11-01 16:11:06 +08:00
<Input placeholder="unavailable choice" id="error" />
2015-10-29 08:41:51 +08:00
</FormItem>
2015-07-07 11:25:16 +08:00
2015-10-29 08:41:51 +08:00
<FormItem
2016-07-31 09:53:51 +08:00
label="Warning"
labelCol={{ span: 5 }}
wrapperCol={{ span: 12 }}
validateStatus="warning"
>
2016-11-01 16:11:06 +08:00
<Input placeholder="Warning" id="warning" />
2015-10-29 08:41:51 +08:00
</FormItem>
2015-10-25 11:35:03 +08:00
2015-10-29 08:41:51 +08:00
<FormItem
2016-07-31 09:53:51 +08:00
label="Validating"
labelCol={{ span: 5 }}
wrapperCol={{ span: 12 }}
2015-11-25 17:47:55 +08:00
hasFeedback
2015-10-29 08:41:51 +08:00
validateStatus="validating"
2016-07-31 09:53:51 +08:00
help="The information is being validated..."
>
2016-11-01 16:11:06 +08:00
<Input placeholder="I'm the content is being validated" id="validating" />
2015-10-29 08:41:51 +08:00
</FormItem>
2015-07-07 11:25:16 +08:00
2015-10-29 08:41:51 +08:00
<FormItem
2016-07-31 09:53:51 +08:00
label="Success"
labelCol={{ span: 5 }}
wrapperCol={{ span: 12 }}
2015-11-25 17:47:55 +08:00
hasFeedback
validateStatus="success"
>
2016-11-01 16:11:06 +08:00
<Input placeholder="I'm the content" id="success" />
2015-10-29 08:41:51 +08:00
</FormItem>
2015-10-25 11:35:03 +08:00
2015-10-29 08:41:51 +08:00
<FormItem
2016-07-31 09:53:51 +08:00
label="Warning"
labelCol={{ span: 5 }}
wrapperCol={{ span: 12 }}
2015-11-25 17:47:55 +08:00
hasFeedback
validateStatus="warning"
>
2016-11-01 16:11:06 +08:00
<Input placeholder="Warning" id="warning" />
2015-10-29 08:41:51 +08:00
</FormItem>
2015-07-07 11:25:16 +08:00
2015-10-29 08:41:51 +08:00
<FormItem
2016-07-31 09:53:51 +08:00
label="Fail"
labelCol={{ span: 5 }}
wrapperCol={{ span: 12 }}
2015-11-25 17:47:55 +08:00
hasFeedback
2015-10-29 08:41:51 +08:00
validateStatus="error"
2016-09-22 10:09:22 +08:00
help="Should be combination of numbers & alphabets"
>
2016-11-01 16:11:06 +08:00
<Input placeholder="unavailable choice" id="error" />
2015-10-29 08:41:51 +08:00
</FormItem>
2015-10-09 15:44:10 +08:00
2015-10-29 08:41:51 +08:00
<FormItem
2016-07-31 09:53:51 +08:00
label="inline"
labelCol={{ span: 5 }}
help
>
2015-10-29 08:41:51 +08:00
<Col span="6">
2016-07-31 09:53:51 +08:00
<FormItem validateStatus="error" help="Please select the correct date">
2016-01-12 14:24:42 +08:00
<DatePicker />
</FormItem>
2015-10-29 08:41:51 +08:00
</Col>
<Col span="1">
<p className="ant-form-split">-</p>
</Col>
<Col span="6">
2016-01-12 14:24:42 +08:00
<FormItem>
<DatePicker />
</FormItem>
2015-10-29 08:41:51 +08:00
</Col>
</FormItem>
</Form>
, mountNode);
2015-06-15 20:24:01 +08:00
````