2016-03-31 09:40:55 +08:00
|
|
|
---
|
2019-07-03 20:14:39 +08:00
|
|
|
order: 20
|
2016-09-01 11:48:38 +08:00
|
|
|
title:
|
2017-02-15 14:39:55 +08:00
|
|
|
zh-CN: 自定义校验
|
|
|
|
en-US: Customized Validation
|
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
|
|
|
|
|
2019-07-03 20:14:39 +08:00
|
|
|
我们提供了 `validateStatus` `help` `hasFeedback` 等属性,你可以不通过 Form 自己定义校验的时机和内容。
|
2015-06-15 20:24:01 +08:00
|
|
|
|
2017-02-15 14:39:55 +08:00
|
|
|
1. `validateStatus`: 校验状态,可选 'success', 'warning', 'error', 'validating'。
|
|
|
|
2. `hasFeedback`:用于给输入框添加反馈图标。
|
|
|
|
3. `help`:设置校验文案。
|
2015-07-07 11:25:16 +08:00
|
|
|
|
2016-07-31 09:53:51 +08:00
|
|
|
## en-US
|
|
|
|
|
2019-07-03 20:14:39 +08:00
|
|
|
We provide properties like `validateStatus` `help` `hasFeedback` to customize your own validate status and message, without using Form.
|
2016-07-31 09:53:51 +08:00
|
|
|
|
2017-02-15 14:39:55 +08:00
|
|
|
1. `validateStatus`: validate status of form components which could be 'success', 'warning', 'error', 'validating'.
|
|
|
|
2. `hasFeedback`: display feed icon of input control
|
|
|
|
3. `help`: display validate message.
|
2016-07-31 09:53:51 +08:00
|
|
|
|
2019-07-03 20:14:39 +08:00
|
|
|
```tsx
|
2020-01-28 12:38:30 +08:00
|
|
|
import { SmileOutlined } from '@ant-design/icons';
|
2019-05-07 14:57:32 +08:00
|
|
|
import { Form, Input, DatePicker, TimePicker, Select, Cascader, InputNumber } from 'antd';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2018-12-22 16:48:30 +08:00
|
|
|
const { Option } = Select;
|
2015-06-15 20:24:01 +08:00
|
|
|
|
2017-03-15 11:25:58 +08:00
|
|
|
const formItemLayout = {
|
|
|
|
labelCol: {
|
|
|
|
xs: { span: 24 },
|
|
|
|
sm: { span: 5 },
|
|
|
|
},
|
|
|
|
wrapperCol: {
|
|
|
|
xs: { span: 24 },
|
|
|
|
sm: { span: 12 },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2015-10-25 11:35:03 +08:00
|
|
|
ReactDOM.render(
|
2019-02-25 19:04:09 +08:00
|
|
|
<Form {...formItemLayout}>
|
2018-12-22 16:48:30 +08:00
|
|
|
<Form.Item
|
2016-07-31 09:53:51 +08:00
|
|
|
label="Fail"
|
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-06-06 13:54:10 +08:00
|
|
|
>
|
2016-11-01 16:11:06 +08:00
|
|
|
<Input placeholder="unavailable choice" id="error" />
|
2018-12-22 16:48:30 +08:00
|
|
|
</Form.Item>
|
2015-07-07 11:25:16 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
<Form.Item label="Warning" validateStatus="warning">
|
2020-01-28 12:38:30 +08:00
|
|
|
<Input placeholder="Warning" id="warning" prefix={<SmileOutlined />} />
|
2018-12-22 16:48:30 +08:00
|
|
|
</Form.Item>
|
2015-10-25 11:35:03 +08:00
|
|
|
|
2018-12-22 16:48:30 +08:00
|
|
|
<Form.Item
|
2016-07-31 09:53:51 +08:00
|
|
|
label="Validating"
|
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-06-06 13:54:10 +08:00
|
|
|
>
|
2016-11-01 16:11:06 +08:00
|
|
|
<Input placeholder="I'm the content is being validated" id="validating" />
|
2018-12-22 16:48:30 +08:00
|
|
|
</Form.Item>
|
2015-07-07 11:25:16 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
<Form.Item label="Success" hasFeedback validateStatus="success">
|
2016-11-01 16:11:06 +08:00
|
|
|
<Input placeholder="I'm the content" id="success" />
|
2018-12-22 16:48:30 +08:00
|
|
|
</Form.Item>
|
2015-10-25 11:35:03 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
<Form.Item label="Warning" hasFeedback validateStatus="warning">
|
2018-12-17 10:02:08 +08:00
|
|
|
<Input placeholder="Warning" id="warning2" />
|
2018-12-22 16:48:30 +08:00
|
|
|
</Form.Item>
|
2015-07-07 11:25:16 +08:00
|
|
|
|
2018-12-22 16:48:30 +08:00
|
|
|
<Form.Item
|
2016-07-31 09:53:51 +08:00
|
|
|
label="Fail"
|
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-06-06 13:54:10 +08:00
|
|
|
>
|
2018-12-17 10:02:08 +08:00
|
|
|
<Input placeholder="unavailable choice" id="error2" />
|
2018-12-22 16:48:30 +08:00
|
|
|
</Form.Item>
|
2015-10-09 15:44:10 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
<Form.Item label="Success" hasFeedback validateStatus="success">
|
2017-09-06 20:17:20 +08:00
|
|
|
<DatePicker style={{ width: '100%' }} />
|
2018-12-22 16:48:30 +08:00
|
|
|
</Form.Item>
|
2017-09-06 20:17:20 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
<Form.Item label="Warning" hasFeedback validateStatus="warning">
|
2017-09-06 20:17:20 +08:00
|
|
|
<TimePicker style={{ width: '100%' }} />
|
2018-12-22 16:48:30 +08:00
|
|
|
</Form.Item>
|
2017-09-06 20:17:20 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
<Form.Item label="Error" hasFeedback validateStatus="error">
|
2020-07-21 16:18:31 +08:00
|
|
|
<Select allowClear>
|
2017-09-06 20:17:20 +08:00
|
|
|
<Option value="1">Option 1</Option>
|
|
|
|
<Option value="2">Option 2</Option>
|
|
|
|
<Option value="3">Option 3</Option>
|
|
|
|
</Select>
|
2018-12-22 16:48:30 +08:00
|
|
|
</Form.Item>
|
2017-09-06 20:17:20 +08:00
|
|
|
|
2018-12-22 16:48:30 +08:00
|
|
|
<Form.Item
|
2017-09-06 20:17:20 +08:00
|
|
|
label="Validating"
|
|
|
|
hasFeedback
|
|
|
|
validateStatus="validating"
|
|
|
|
help="The information is being validated..."
|
|
|
|
>
|
2020-07-21 16:18:31 +08:00
|
|
|
<Cascader options={[{ value: 'xx', label: 'xx' }]} allowClear />
|
2018-12-22 16:48:30 +08:00
|
|
|
</Form.Item>
|
2017-09-06 20:17:20 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
<Form.Item label="inline" style={{ marginBottom: 0 }}>
|
2018-12-22 16:48:30 +08:00
|
|
|
<Form.Item
|
2018-12-22 16:44:10 +08:00
|
|
|
validateStatus="error"
|
|
|
|
help="Please select the correct date"
|
|
|
|
style={{ display: 'inline-block', width: 'calc(50% - 12px)' }}
|
|
|
|
>
|
|
|
|
<DatePicker />
|
2018-12-22 16:48:30 +08:00
|
|
|
</Form.Item>
|
2020-03-30 21:23:05 +08:00
|
|
|
<span
|
|
|
|
style={{ display: 'inline-block', width: '24px', lineHeight: '32px', textAlign: 'center' }}
|
|
|
|
>
|
|
|
|
-
|
|
|
|
</span>
|
2019-05-07 14:57:32 +08:00
|
|
|
<Form.Item style={{ display: 'inline-block', width: 'calc(50% - 12px)' }}>
|
2018-12-22 16:44:10 +08:00
|
|
|
<DatePicker />
|
2018-12-22 16:48:30 +08:00
|
|
|
</Form.Item>
|
|
|
|
</Form.Item>
|
2017-09-06 20:17:20 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
<Form.Item label="Success" hasFeedback validateStatus="success">
|
2017-09-06 20:17:20 +08:00
|
|
|
<InputNumber style={{ width: '100%' }} />
|
2018-12-22 16:48:30 +08:00
|
|
|
</Form.Item>
|
2019-12-20 16:24:55 +08:00
|
|
|
|
|
|
|
<Form.Item label="Success" hasFeedback validateStatus="success">
|
|
|
|
<Input allowClear placeholder="with allowClear" />
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
<Form.Item label="Warning" hasFeedback validateStatus="warning">
|
|
|
|
<Input.Password placeholder="with input password" />
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
<Form.Item label="Error" hasFeedback validateStatus="error">
|
|
|
|
<Input.Password allowClear placeholder="with input password and allowClear" />
|
|
|
|
</Form.Item>
|
2018-06-27 15:55:04 +08:00
|
|
|
</Form>,
|
2019-05-07 14:57:32 +08:00
|
|
|
mountNode,
|
2018-11-28 15:00:03 +08:00
|
|
|
);
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|