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

143 lines
4.5 KiB
Markdown
Raw Normal View History

2015-07-07 11:25:16 +08:00
# 表单组合
2015-10-29 08:41:51 +08:00
- order: 5
2015-07-07 11:25:16 +08:00
2015-07-07 23:45:46 +08:00
集中营,展示和表单相关的其他 ant-design 组件。
2015-07-07 11:25:16 +08:00
---
````jsx
2015-12-31 09:51:44 +08:00
import { Form, Select, InputNumber, DatePicker, Switch,
Slider, Button, message, Row, Col, Upload, Icon } from 'antd';
2015-10-29 08:41:51 +08:00
const FormItem = Form.Item;
const Option = Select.Option;
2015-07-07 11:25:16 +08:00
const Demo = React.createClass({
2015-10-25 11:35:03 +08:00
mixins: [Form.ValueMixin],
2015-07-07 11:25:16 +08:00
2015-10-25 11:35:03 +08:00
getInitialState() {
return {
formData: {
inputNumber: undefined,
static: '唧唧复唧唧木兰当户织呀',
2015-10-25 11:35:03 +08:00
switch: undefined,
slider: undefined,
select: undefined,
startDate: undefined,
endDate: undefined,
}
};
},
2015-07-07 11:25:16 +08:00
2015-12-31 09:51:44 +08:00
handleUpload(info) {
if (info.file.status !== 'uploading') {
console.log(info.file, info.fileList);
}
if (info.file.status === 'done') {
message.success(info.file.name + ' 上传成功。');
} else if (info.file.status === 'error') {
message.error(info.file.name + ' 上传失败。');
}
},
2015-10-25 11:35:03 +08:00
handleSubmit(e) {
e.preventDefault();
message.success('收到表单值~~~ ' + JSON.stringify(this.state.formData, function(k, v) {
2015-10-27 19:23:45 +08:00
if (typeof v === 'undefined') {
return '';
}
return v;
}));
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() {
const formData = this.state.formData;
2015-10-25 11:35:03 +08:00
return (
<Form horizontal onSubmit={this.handleSubmit} >
2015-10-29 08:41:51 +08:00
<FormItem
2015-10-25 11:35:03 +08:00
label="InputNumber 数字输入框:"
2015-10-29 08:41:51 +08:00
labelCol={{span: 8}}
wrapperCol={{span: 10}}
2015-11-25 17:47:55 +08:00
required>
2015-10-25 11:35:03 +08:00
<InputNumber size="large" min={1} max={10} style={{width:100}} defaultValue={3} name="inputNumber" onChange={this.setValue.bind(this, 'inputNumber')} value={formData.inputNumber} />
<span className="ant-form-text"> 台机器</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
2015-10-25 11:35:03 +08:00
label="我是标题:"
2015-10-29 08:41:51 +08:00
labelCol={{span: 8}}
wrapperCol={{span: 10}}
2015-11-25 17:47:55 +08:00
required>
2015-10-29 08:41:51 +08:00
<p className="ant-form-text" id="static" name="static">唧唧复唧唧木兰当户织呀</p>
2015-10-25 11:35:03 +08:00
<p className="ant-form-text">
<a href="#">链接文字</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
2015-10-25 11:35:03 +08:00
label="Switch 开关:"
2015-10-29 08:41:51 +08:00
labelCol={{span: 8}}
wrapperCol={{span: 10}}
2015-11-25 17:47:55 +08:00
required>
2015-10-25 11:35:03 +08:00
<Switch name="switch" onChange={this.setValue.bind(this, 'switch')} value={formData.switch} />
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
2015-10-25 11:35:03 +08:00
label="Slider 滑动输入条:"
2015-10-29 08:41:51 +08:00
labelCol={{span: 8}}
wrapperCol={{span: 10}}
2015-11-25 17:47:55 +08:00
required>
<Slider marks={['A', 'B', 'C', 'D', 'E', 'F', 'G']} name="slider" onChange={this.setValue.bind(this, '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
2015-10-25 11:35:03 +08:00
label="Select 选择器:"
2015-10-29 08:41:51 +08:00
labelCol={{span: 8}}
wrapperCol={{span: 16}}
2015-11-25 17:47:55 +08:00
required>
2015-10-25 11:35:03 +08:00
<Select size="large" defaultValue="lucy" style={{width:200}} name="select" onChange={this.setValue.bind(this, 'select')} value={formData.select}>
<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
2015-10-29 08:41:51 +08:00
<FormItem
label="DatePicker 日期选择框:"
2015-10-29 08:41:51 +08:00
labelCol={{span: 8}}
2015-11-25 17:47:55 +08:00
required>
2015-10-29 08:41:51 +08:00
<Col span="6">
<DatePicker name="startDate" onChange={this.setValue.bind(this, 'startDate')} value={formData.startDate} />
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">
<DatePicker name="endDate" onChange={this.setValue.bind(this, 'endDate')} value={formData.endDate} />
2015-10-29 08:41:51 +08:00
</Col>
</FormItem>
2015-12-31 09:51:44 +08:00
<FormItem
label="logo图"
labelCol={{span: 8}}
wrapperCol={{span: 16}}
help="提示信息要长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长">
2015-12-31 09:51:44 +08:00
<Upload name="logo" action="/upload.do" listType="picture" onChange={this.handleUpload}>
<Button type="ghost">
<Icon type="upload" /> 点击上传
</Button>
</Upload>
</FormItem>
2015-10-29 08:41:51 +08:00
<Row>
<Col span="16" offset="8">
2015-10-25 11:35:03 +08:00
<Button type="primary" htmlType="submit">确定</Button>
2015-10-29 08:41:51 +08:00
</Col>
</Row>
2015-10-25 11:35:03 +08:00
</Form>
);
}
});
2015-10-09 15:44:10 +08:00
ReactDOM.render(<Demo />, mountNode);
2015-07-16 13:00:56 +08:00
````