2015-07-07 11:25:16 +08:00
|
|
|
# 水平排列的表单
|
2015-06-15 20:24:01 +08:00
|
|
|
|
2015-10-29 08:41:51 +08:00
|
|
|
- order: 2
|
2015-06-15 20:24:01 +08:00
|
|
|
|
2016-01-30 19:00:56 +08:00
|
|
|
示例展示了如何通过使用 `Form.create` 来获取和更新表单提交的数值。
|
2015-07-17 15:12:48 +08:00
|
|
|
|
2015-06-15 20:24:01 +08:00
|
|
|
---
|
|
|
|
|
2015-07-20 20:35:48 +08:00
|
|
|
````jsx
|
2016-01-23 15:22:16 +08:00
|
|
|
import { Form, Input, Button, Checkbox, Radio, Row, Col } from 'antd';
|
2015-10-29 08:41:51 +08:00
|
|
|
const FormItem = Form.Item;
|
|
|
|
const RadioGroup = Radio.Group;
|
2015-07-20 20:35:48 +08:00
|
|
|
|
2016-01-30 19:00:56 +08:00
|
|
|
let Demo = React.createClass({
|
2015-10-25 11:35:03 +08:00
|
|
|
handleSubmit(e) {
|
|
|
|
e.preventDefault();
|
2016-01-30 19:00:56 +08:00
|
|
|
console.log('收到表单值:', this.props.form.getFieldsValue());
|
2015-10-25 11:35:03 +08:00
|
|
|
},
|
2015-10-09 15:44:10 +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
|
2015-10-25 11:35:03 +08:00
|
|
|
label="用户名:"
|
2016-01-27 16:44:50 +08:00
|
|
|
labelCol={{ span: 6 }}
|
2016-01-30 19:00:56 +08:00
|
|
|
wrapperCol={{ span: 14 }}>
|
2015-10-29 08:41:51 +08:00
|
|
|
<p className="ant-form-text" id="userName" name="userName">大眼萌 minion</p>
|
|
|
|
</FormItem>
|
|
|
|
<FormItem
|
2015-10-25 11:35:03 +08:00
|
|
|
label="密码:"
|
2016-01-27 16:44:50 +08:00
|
|
|
labelCol={{ span: 6 }}
|
2016-01-30 19:00:56 +08:00
|
|
|
wrapperCol={{ span: 14 }}>
|
|
|
|
<Input type="password" {...getFieldProps('pass')} placeholder="请输入密码" />
|
2015-10-29 08:41:51 +08:00
|
|
|
</FormItem>
|
|
|
|
<FormItem
|
2015-10-25 11:35:03 +08:00
|
|
|
label="您的性别:"
|
2016-01-27 16:44:50 +08:00
|
|
|
labelCol={{ span: 6 }}
|
2016-01-30 19:00:56 +08:00
|
|
|
wrapperCol={{ span: 14 }}d>
|
|
|
|
<RadioGroup {...getFieldProps('gender', { initialValue: 'female' })}>
|
2015-10-25 11:35:03 +08:00
|
|
|
<Radio value="male">男的</Radio>
|
|
|
|
<Radio value="female">女的</Radio>
|
|
|
|
</RadioGroup>
|
2015-10-29 08:41:51 +08:00
|
|
|
</FormItem>
|
|
|
|
<FormItem
|
2015-10-25 11:35:03 +08:00
|
|
|
label="备注:"
|
2016-01-27 16:44:50 +08:00
|
|
|
labelCol={{ span: 6 }}
|
|
|
|
wrapperCol={{ span: 14 }}
|
2015-11-25 17:47:55 +08:00
|
|
|
help="随便写点什么">
|
2016-01-30 19:00:56 +08:00
|
|
|
<Input type="textarea" placeholder="随便写" {...getFieldProps('remark')} />
|
2015-10-29 08:41:51 +08:00
|
|
|
</FormItem>
|
|
|
|
<FormItem
|
2016-01-27 16:44:50 +08:00
|
|
|
wrapperCol={{ span: 14, offset: 6 }} >
|
2015-10-25 11:35:03 +08:00
|
|
|
<label>
|
2016-01-30 19:00:56 +08:00
|
|
|
<Checkbox {...getFieldProps('agreement')} />同意
|
2015-10-25 11:35:03 +08:00
|
|
|
</label>
|
2015-10-29 08:41:51 +08:00
|
|
|
</FormItem>
|
|
|
|
<Row>
|
|
|
|
<Col span="16" offset="6">
|
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-29 08:41:51 +08:00
|
|
|
|
2016-01-30 19:00:56 +08:00
|
|
|
Demo = Form.create()(Demo);
|
|
|
|
|
2015-12-29 12:08:58 +08:00
|
|
|
ReactDOM.render(<Demo />, mountNode);
|
2015-06-15 20:24:01 +08:00
|
|
|
````
|