mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-02 15:59:38 +08:00
2bced36f0c
* Tweak button padding
* upgrade input and button size
* update form controls size
* update components size
* Add lemon color and update rate color
* Add new icons
* update layout style
* breadcrumb and dropdown
* update menu arrow width
* update layout and menu
* update steps
* fix var name
* update cascasder style
* Update DatePicker
* update InputNumber and Mention
* radio and switch
* select and transfer
* TimePicker & Upload
* more components
* calendar and list
* Tree Timeline Popover Tag
* divider modal popover
* update search input
* update card style
* update switch disabled opacity
* update shoadow and mask
* Add v2-compatible-reset.less
* Fix undefined className
* update snahshotssssssssssssssssss 👻
202 lines
5.3 KiB
Markdown
202 lines
5.3 KiB
Markdown
---
|
|
order: 14
|
|
title:
|
|
zh-CN: 校验其他组件
|
|
en-US: Other Form Controls
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
以上演示没有出现的表单控件对应的校验演示。
|
|
|
|
## en-US
|
|
|
|
Demostration for validataion configuration for form controls which are not show in the above demos.
|
|
|
|
````jsx
|
|
import {
|
|
Form, Select, InputNumber, Switch, Radio,
|
|
Slider, Button, Upload, Icon,
|
|
} from 'antd';
|
|
const FormItem = Form.Item;
|
|
const Option = Select.Option;
|
|
const RadioButton = Radio.Button;
|
|
const RadioGroup = Radio.Group;
|
|
|
|
class Demo extends React.Component {
|
|
handleSubmit = (e) => {
|
|
e.preventDefault();
|
|
this.props.form.validateFields((err, values) => {
|
|
if (!err) {
|
|
console.log('Received values of form: ', values);
|
|
}
|
|
});
|
|
}
|
|
normFile = (e) => {
|
|
console.log('Upload event:', e);
|
|
if (Array.isArray(e)) {
|
|
return e;
|
|
}
|
|
return e && e.fileList;
|
|
}
|
|
render() {
|
|
const { getFieldDecorator } = this.props.form;
|
|
const formItemLayout = {
|
|
labelCol: { span: 6 },
|
|
wrapperCol: { span: 14 },
|
|
};
|
|
return (
|
|
<Form onSubmit={this.handleSubmit}>
|
|
<FormItem
|
|
{...formItemLayout}
|
|
label="Plain Text"
|
|
>
|
|
<span className="ant-form-text">China</span>
|
|
</FormItem>
|
|
<FormItem
|
|
{...formItemLayout}
|
|
label="Select"
|
|
hasFeedback
|
|
>
|
|
{getFieldDecorator('select', {
|
|
rules: [
|
|
{ required: true, message: 'Please select your country!' },
|
|
],
|
|
})(
|
|
<Select placeholder="Please select a country">
|
|
<Option value="china">China</Option>
|
|
<Option value="use">U.S.A</Option>
|
|
</Select>
|
|
)}
|
|
</FormItem>
|
|
|
|
<FormItem
|
|
{...formItemLayout}
|
|
label="Select[multiple]"
|
|
>
|
|
{getFieldDecorator('select-multiple', {
|
|
rules: [
|
|
{ required: true, message: 'Please select your favourite colors!', type: 'array' },
|
|
],
|
|
})(
|
|
<Select mode="multiple" placeholder="Please select favourite colors">
|
|
<Option value="red">Red</Option>
|
|
<Option value="green">Green</Option>
|
|
<Option value="blue">Blue</Option>
|
|
</Select>
|
|
)}
|
|
</FormItem>
|
|
|
|
<FormItem
|
|
{...formItemLayout}
|
|
label="InputNumber"
|
|
>
|
|
{getFieldDecorator('input-number', { initialValue: 3 })(
|
|
<InputNumber min={1} max={10} />
|
|
)}
|
|
<span className="ant-form-text"> machines</span>
|
|
</FormItem>
|
|
|
|
<FormItem
|
|
{...formItemLayout}
|
|
label="Switch"
|
|
>
|
|
{getFieldDecorator('switch', { valuePropName: 'checked' })(
|
|
<Switch />
|
|
)}
|
|
</FormItem>
|
|
|
|
<FormItem
|
|
{...formItemLayout}
|
|
label="Slider"
|
|
>
|
|
{getFieldDecorator('slider')(
|
|
<Slider marks={{ 0: 'A', 20: 'B', 40: 'C', 60: 'D', 80: 'E', 100: 'F' }} />
|
|
)}
|
|
</FormItem>
|
|
|
|
<FormItem
|
|
{...formItemLayout}
|
|
label="Radio.Group"
|
|
>
|
|
{getFieldDecorator('radio-group')(
|
|
<RadioGroup>
|
|
<Radio value="a">item 1</Radio>
|
|
<Radio value="b">item 2</Radio>
|
|
<Radio value="c">item 3</Radio>
|
|
</RadioGroup>
|
|
)}
|
|
</FormItem>
|
|
|
|
<FormItem
|
|
{...formItemLayout}
|
|
label="Radio.Button"
|
|
>
|
|
{getFieldDecorator('radio-button')(
|
|
<RadioGroup>
|
|
<RadioButton value="a">item 1</RadioButton>
|
|
<RadioButton value="b">item 2</RadioButton>
|
|
<RadioButton value="c">item 3</RadioButton>
|
|
</RadioGroup>
|
|
)}
|
|
</FormItem>
|
|
|
|
<FormItem
|
|
{...formItemLayout}
|
|
label="Upload"
|
|
extra="longgggggggggggggggggggggggggggggggggg"
|
|
>
|
|
{getFieldDecorator('upload', {
|
|
valuePropName: 'fileList',
|
|
getValueFromEvent: this.normFile,
|
|
})(
|
|
<Upload name="logo" action="/upload.do" listType="picture">
|
|
<Button>
|
|
<Icon type="upload" /> Click to upload
|
|
</Button>
|
|
</Upload>
|
|
)}
|
|
</FormItem>
|
|
|
|
<FormItem
|
|
{...formItemLayout}
|
|
label="Dragger"
|
|
>
|
|
<div className="dropbox">
|
|
{getFieldDecorator('dragger', {
|
|
valuePropName: 'fileList',
|
|
getValueFromEvent: this.normFile,
|
|
})(
|
|
<Upload.Dragger name="files" action="/upload.do">
|
|
<p className="ant-upload-drag-icon">
|
|
<Icon type="inbox" />
|
|
</p>
|
|
<p className="ant-upload-text">Click or drag file to this area to upload</p>
|
|
<p className="ant-upload-hint">Support for a single or bulk upload.</p>
|
|
</Upload.Dragger>
|
|
)}
|
|
</div>
|
|
</FormItem>
|
|
|
|
<FormItem
|
|
wrapperCol={{ span: 12, offset: 6 }}
|
|
>
|
|
<Button type="primary" htmlType="submit">Submit</Button>
|
|
</FormItem>
|
|
</Form>
|
|
);
|
|
}
|
|
}
|
|
|
|
const WrappedDemo = Form.create()(Demo);
|
|
|
|
ReactDOM.render(<WrappedDemo />, mountNode);
|
|
````
|
|
|
|
````css
|
|
#components-form-demo-validate-other .dropbox {
|
|
height: 180px;
|
|
line-height: 1.5;
|
|
}
|
|
````
|