2015-07-07 11:25:16 +08:00
|
|
|
|
# 表单组合
|
|
|
|
|
|
2015-07-07 23:45:46 +08:00
|
|
|
|
- order: 7
|
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-10-09 15:44:10 +08:00
|
|
|
|
var Form = antd.Form;
|
2015-07-07 11:25:16 +08:00
|
|
|
|
var Select = antd.Select;
|
|
|
|
|
var Option = Select.Option;
|
|
|
|
|
var InputNumber = antd.InputNumber;
|
|
|
|
|
var Datepicker = antd.Datepicker;
|
2015-07-08 19:47:45 +08:00
|
|
|
|
var Switch = antd.Switch;
|
2015-07-09 10:55:37 +08:00
|
|
|
|
var Menu = antd.Menu;
|
|
|
|
|
var Dropdown = antd.Dropdown;
|
2015-07-15 16:00:59 +08:00
|
|
|
|
var Slider = antd.Slider;
|
2015-10-02 15:17:21 +08:00
|
|
|
|
var Icon = antd.Icon;
|
2015-10-25 11:35:03 +08:00
|
|
|
|
var Button = antd.Button;
|
2015-10-27 19:23:45 +08:00
|
|
|
|
var message = antd.message;
|
2015-07-07 11:25:16 +08:00
|
|
|
|
|
2015-10-25 11:35:03 +08:00
|
|
|
|
var Demo = React.createClass({
|
|
|
|
|
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: "唧唧复唧唧木兰当户织呀",
|
|
|
|
|
switch: undefined,
|
|
|
|
|
slider: undefined,
|
|
|
|
|
select: undefined,
|
|
|
|
|
startDate: undefined,
|
|
|
|
|
endDate: undefined,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
},
|
2015-07-07 11:25:16 +08:00
|
|
|
|
|
2015-10-25 11:35:03 +08:00
|
|
|
|
handleSubmit(e) {
|
|
|
|
|
e.preventDefault();
|
2015-10-27 19:23:45 +08:00
|
|
|
|
message.success("收到表单值~~~ :" + JSON.stringify(this.state.formData, function(k, v) {
|
|
|
|
|
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() {
|
|
|
|
|
var formData = this.state.formData;
|
|
|
|
|
return (
|
|
|
|
|
<Form horizontal onSubmit={this.handleSubmit} >
|
|
|
|
|
<Form.Item
|
|
|
|
|
label="InputNumber 数字输入框:"
|
|
|
|
|
labelClassName="col-8"
|
|
|
|
|
wrapperClassName="col-10"
|
|
|
|
|
required={true} >
|
|
|
|
|
<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>
|
|
|
|
|
</Form.Item>
|
2015-10-09 15:44:10 +08:00
|
|
|
|
|
2015-10-25 11:35:03 +08:00
|
|
|
|
<Form.Item
|
|
|
|
|
label="我是标题:"
|
|
|
|
|
labelClassName="col-8"
|
|
|
|
|
wrapperClassName="col-10"
|
|
|
|
|
required={true} >
|
|
|
|
|
<Form.Input type="static" id="static" name="static" onChange={this.setValue.bind(this, 'static')} value="唧唧复唧唧木兰当户织呀" />
|
|
|
|
|
<p className="ant-form-text">
|
|
|
|
|
<a href="javascript:;">链接文字</a>
|
|
|
|
|
</p>
|
|
|
|
|
</Form.Item>
|
2015-10-09 15:44:10 +08:00
|
|
|
|
|
2015-10-25 11:35:03 +08:00
|
|
|
|
<Form.Item
|
|
|
|
|
label="Switch 开关:"
|
|
|
|
|
labelClassName="col-8"
|
|
|
|
|
wrapperClassName="col-10"
|
|
|
|
|
required={true} >
|
|
|
|
|
<Switch name="switch" onChange={this.setValue.bind(this, 'switch')} value={formData.switch} />
|
|
|
|
|
</Form.Item>
|
2015-10-09 15:44:10 +08:00
|
|
|
|
|
2015-10-25 11:35:03 +08:00
|
|
|
|
<Form.Item
|
|
|
|
|
label="Slider 滑动输入条:"
|
|
|
|
|
labelClassName="col-8"
|
|
|
|
|
wrapperClassName="col-10"
|
|
|
|
|
required={true}>
|
|
|
|
|
<Slider marks={["A","B","C","D","E","F","G"]} name="slider" onChange={this.setValue.bind(this, 'slider')} />
|
|
|
|
|
</Form.Item>
|
2015-10-09 15:44:10 +08:00
|
|
|
|
|
2015-10-25 11:35:03 +08:00
|
|
|
|
<Form.Item
|
|
|
|
|
label="Select 选择器:"
|
|
|
|
|
labelClassName="col-8"
|
|
|
|
|
wrapperClassName="col-16"
|
|
|
|
|
required={true}>
|
|
|
|
|
<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>
|
|
|
|
|
</Form.Item>
|
2015-10-09 15:44:10 +08:00
|
|
|
|
|
2015-10-25 11:35:03 +08:00
|
|
|
|
<Form.Item
|
|
|
|
|
label="Datepicker 日期选择框:"
|
|
|
|
|
labelClassName="col-8"
|
|
|
|
|
required={true}>
|
|
|
|
|
<div className="col-6">
|
|
|
|
|
<Datepicker name="startDate" onChange={this.setValue.bind(this, 'startDate')} value={formData.startDate} />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="col-1">
|
|
|
|
|
<p className="ant-form-split">-</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="col-6">
|
|
|
|
|
<Datepicker name="endDate" onChange={this.setValue.bind(this, 'endDate')} value={formData.endDate} />
|
|
|
|
|
</div>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<div className="row">
|
|
|
|
|
<div className="col-16 col-offset-8">
|
|
|
|
|
<Button type="primary" htmlType="submit">确定</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Form>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-10-09 15:44:10 +08:00
|
|
|
|
|
2015-10-25 11:35:03 +08:00
|
|
|
|
ReactDOM.render(<Demo />, document.getElementById('components-form-demo-mix'));
|
2015-07-16 13:00:56 +08:00
|
|
|
|
````
|