ant-design/components/form/demo/mix.md

191 lines
4.9 KiB
Markdown
Raw Normal View History

2016-03-31 09:40:55 +08:00
---
order: 5
2016-07-31 09:53:51 +08:00
title:
zh-CN: 表单组合
en-US: mix
2016-03-31 09:40:55 +08:00
---
2015-07-07 11:25:16 +08:00
2016-07-31 09:53:51 +08:00
## zh-CN
2015-07-07 23:45:46 +08:00
集中营,展示和表单相关的其他 ant-design 组件。
2015-07-07 11:25:16 +08:00
2016-07-31 09:53:51 +08:00
## en-US
A mix to demonstrate others ant-design component related to form.
2015-07-07 11:25:16 +08:00
````jsx
2016-01-27 12:00:27 +08:00
import { Form, Select, InputNumber, DatePicker, TimePicker, Switch, Radio,
Cascader, Slider, Button, Col, Upload, Icon } from 'antd';
2015-10-29 08:41:51 +08:00
const FormItem = Form.Item;
const Option = Select.Option;
const RadioButton = Radio.Button;
const RadioGroup = Radio.Group;
2015-07-07 11:25:16 +08:00
const areaData = [{
value: 'shanghai',
2016-07-31 09:53:51 +08:00
label: 'Shanghai',
children: [{
value: 'shanghaishi',
2016-07-31 09:53:51 +08:00
label: 'Shanghai',
children: [{
value: 'pudongxinqu',
2016-07-31 09:53:51 +08:00
label: 'Pudong New District',
}],
}],
}];
2016-01-30 19:00:56 +08:00
let Demo = React.createClass({
handleSubmit(e) {
e.preventDefault();
2016-07-31 09:53:51 +08:00
console.log('Received the values of form', this.props.form.getFieldsValue());
2015-10-25 11:35:03 +08:00
},
2015-07-07 11:25:16 +08:00
2016-01-30 19:00:56 +08:00
normFile(e) {
if (Array.isArray(e)) {
return e;
2015-12-31 09:51:44 +08:00
}
2016-01-30 19:00:56 +08:00
return e && e.fileList;
2015-10-25 11:35:03 +08:00
},
2015-07-07 11:25:16 +08:00
2015-10-25 11:35:03 +08:00
render() {
2016-01-30 19:00:56 +08:00
const { getFieldProps } = this.props.form;
2015-10-25 11:35:03 +08:00
return (
<Form horizontal onSubmit={this.handleSubmit} >
2015-10-29 08:41:51 +08:00
<FormItem
2016-07-31 09:53:51 +08:00
label="InputNumber Control"
labelCol={{ span: 8 }}
wrapperCol={{ span: 10 }}
>
2016-01-30 19:00:56 +08:00
<InputNumber min={1} max={10} style={{ width: 100 }}
{...getFieldProps('inputNumber', { initialValue: 3 })}
/>
2016-07-31 09:53:51 +08:00
<span className="ant-form-text"> machines</span>
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="I'm the title"
labelCol={{ span: 8 }}
wrapperCol={{ span: 10 }}
>
2016-07-31 09:53:51 +08:00
<p className="ant-form-text" id="static" name="static">O, wind, if winter comes, can spring be far behind?</p>
2015-10-25 11:35:03 +08:00
<p className="ant-form-text">
2016-07-31 09:53:51 +08:00
<a href="#">link</a>
2015-10-25 11:35:03 +08:00
</p>
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="Switch"
labelCol={{ span: 8 }}
wrapperCol={{ span: 10 }}
required
>
2016-04-29 15:19:46 +08:00
<Switch {...getFieldProps('switch', { valuePropName: 'checked' })} />
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="Slider"
labelCol={{ span: 8 }}
wrapperCol={{ span: 10 }}
required
>
<Slider marks={['A', 'B', 'C', 'D', 'E', 'F', 'G']} {...getFieldProps('slider')} />
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="Select"
labelCol={{ span: 8 }}
wrapperCol={{ span: 16 }}
required
>
2016-01-30 19:00:56 +08:00
<Select style={{ width: 200 }}
{...getFieldProps('select')}
>
2015-10-25 11:35:03 +08:00
<Option value="jack">jack</Option>
<Option value="lucy">lucy</Option>
<Option value="disabled" disabled>disabled</Option>
<Option value="yiminghe">yiminghe</Option>
</Select>
2015-10-29 08:41:51 +08:00
</FormItem>
2015-10-09 15:44:10 +08:00
<FormItem
2016-07-31 09:53:51 +08:00
label="Cascader"
labelCol={{ span: 8 }}
wrapperCol={{ span: 16 }}
required
hasFeedback
>
<Cascader style={{ width: 200 }} options={areaData} {...getFieldProps('area')} />
</FormItem>
2015-10-29 08:41:51 +08:00
<FormItem
2016-07-31 09:53:51 +08:00
label="DatePicker"
labelCol={{ span: 8 }}
required
>
2015-10-29 08:41:51 +08:00
<Col span="6">
2016-05-19 15:21:48 +08:00
<FormItem>
<DatePicker {...getFieldProps('startDate')} />
</FormItem>
2015-10-29 08:41:51 +08:00
</Col>
<Col span="1">
2015-10-25 11:35:03 +08:00
<p className="ant-form-split">-</p>
2015-10-29 08:41:51 +08:00
</Col>
<Col span="6">
2016-05-19 15:21:48 +08:00
<FormItem>
<DatePicker {...getFieldProps('endDate')} />
</FormItem>
2015-10-29 08:41:51 +08:00
</Col>
</FormItem>
2016-01-27 12:00:27 +08:00
2016-05-19 15:21:48 +08:00
2016-01-27 12:00:27 +08:00
<FormItem
2016-07-31 09:53:51 +08:00
label="TimePicker"
labelCol={{ span: 8 }}
wrapperCol={{ span: 16 }}
required
>
<TimePicker {...getFieldProps('time')} />
2016-01-27 12:00:27 +08:00
</FormItem>
<FormItem
2016-07-31 09:53:51 +08:00
label="Options"
labelCol={{ span: 8 }}
>
2016-01-30 19:00:56 +08:00
<RadioGroup {...getFieldProps('rg')}>
2016-07-31 09:53:51 +08:00
<RadioButton value="a">item 1</RadioButton>
<RadioButton value="b">item 2</RadioButton>
<RadioButton value="c">item 3</RadioButton>
</RadioGroup>
</FormItem>
2015-12-31 09:51:44 +08:00
<FormItem
2016-07-31 09:53:51 +08:00
label="logo"
labelCol={{ span: 8 }}
wrapperCol={{ span: 16 }}
2016-07-31 09:53:51 +08:00
help="longgggggggggggggggggggggggggggggggggg"
>
2016-01-30 19:00:56 +08:00
<Upload name="logo" action="/upload.do" listType="picture" onChange={this.handleUpload}
{...getFieldProps('upload', {
valuePropName: 'fileList',
2016-05-11 09:32:33 +08:00
normalize: this.normFile,
2016-01-30 19:00:56 +08:00
})}
>
2015-12-31 09:51:44 +08:00
<Button type="ghost">
2016-07-31 09:53:51 +08:00
<Icon type="upload" /> Click to upload
2015-12-31 09:51:44 +08:00
</Button>
</Upload>
</FormItem>
2016-04-06 19:30:23 +08:00
<FormItem wrapperCol={{ span: 16, offset: 8 }} style={{ marginTop: 24 }}>
2016-07-31 09:53:51 +08:00
<Button type="primary" htmlType="submit">OK</Button>
2016-04-06 19:30:23 +08:00
</FormItem>
2015-10-25 11:35:03 +08:00
</Form>
);
2016-05-11 09:32:33 +08:00
},
2015-10-25 11:35:03 +08:00
});
2015-10-09 15:44:10 +08:00
2016-01-30 19:00:56 +08:00
Demo = Form.create()(Demo);
ReactDOM.render(<Demo />, mountNode);
2015-07-16 13:00:56 +08:00
````