2016-03-31 09:40:55 +08:00
|
|
|
---
|
|
|
|
order: 2
|
2016-07-31 09:53:51 +08:00
|
|
|
title:
|
|
|
|
zh-CN: 典型表单
|
|
|
|
en-US: Horizontal form
|
2016-03-31 09:40:55 +08:00
|
|
|
---
|
2015-06-15 20:24:01 +08:00
|
|
|
|
2016-07-31 09:53:51 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2016-01-30 19:00:56 +08:00
|
|
|
示例展示了如何通过使用 `Form.create` 来获取和更新表单提交的数值。
|
2015-07-17 15:12:48 +08:00
|
|
|
|
2016-07-31 09:53:51 +08:00
|
|
|
## en-US
|
|
|
|
|
|
|
|
How to use `Form.create` to get and update values of form.
|
|
|
|
|
2015-07-20 20:35:48 +08:00
|
|
|
````jsx
|
2016-04-06 19:30:23 +08:00
|
|
|
import { Form, Input, Button, Checkbox, Radio, Tooltip, Icon } 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-07-31 09:53:51 +08:00
|
|
|
console.log('Received values of form:', 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;
|
2016-03-02 17:31:27 +08:00
|
|
|
const formItemLayout = {
|
|
|
|
labelCol: { span: 6 },
|
|
|
|
wrapperCol: { span: 14 },
|
|
|
|
};
|
2015-10-25 11:35:03 +08:00
|
|
|
return (
|
|
|
|
<Form horizontal onSubmit={this.handleSubmit}>
|
2015-10-29 08:41:51 +08:00
|
|
|
<FormItem
|
2016-03-02 17:31:27 +08:00
|
|
|
{...formItemLayout}
|
2016-07-31 09:53:51 +08:00
|
|
|
label="User name"
|
2016-06-06 13:54:10 +08:00
|
|
|
>
|
2016-07-31 09:53:51 +08:00
|
|
|
<p className="ant-form-text" id="userName" name="userName">Big eye minion</p>
|
2015-10-29 08:41:51 +08:00
|
|
|
</FormItem>
|
|
|
|
<FormItem
|
2016-03-02 17:31:27 +08:00
|
|
|
{...formItemLayout}
|
2016-07-31 09:53:51 +08:00
|
|
|
label="Password"
|
2016-06-06 13:54:10 +08:00
|
|
|
>
|
2016-07-31 09:53:51 +08:00
|
|
|
<Input type="password" {...getFieldProps('pass', { initialValue: '' })} placeholder="Please input the password" />
|
2015-10-29 08:41:51 +08:00
|
|
|
</FormItem>
|
|
|
|
<FormItem
|
2016-03-02 17:31:27 +08:00
|
|
|
{...formItemLayout}
|
2016-07-31 09:53:51 +08:00
|
|
|
label="Gender"
|
2016-06-06 13:54:10 +08:00
|
|
|
>
|
2016-03-02 17:11:12 +08:00
|
|
|
<RadioGroup {...getFieldProps('gender', { initialValue: 'female' })}>
|
2016-07-31 09:53:51 +08:00
|
|
|
<Radio value="male">male</Radio>
|
|
|
|
<Radio value="female">female</Radio>
|
2016-03-02 17:11:12 +08:00
|
|
|
</RadioGroup>
|
2015-10-29 08:41:51 +08:00
|
|
|
</FormItem>
|
|
|
|
<FormItem
|
2016-03-02 17:31:27 +08:00
|
|
|
{...formItemLayout}
|
2016-07-31 09:53:51 +08:00
|
|
|
label="remarks"
|
|
|
|
help="Please input something"
|
2016-06-06 13:54:10 +08:00
|
|
|
>
|
2016-07-31 09:53:51 +08:00
|
|
|
<Input type="textarea" placeholder="Please input something" {...getFieldProps('remark', { initialValue: '' })} />
|
2015-10-29 08:41:51 +08:00
|
|
|
</FormItem>
|
|
|
|
<FormItem
|
2016-03-02 17:31:27 +08:00
|
|
|
{...formItemLayout}
|
2016-08-04 17:45:15 +08:00
|
|
|
label={<span>Sold myself <Tooltip title="I come for Qiu Xiang"><Icon type="question-circle-o" /></Tooltip></span>}
|
2016-06-06 13:54:10 +08:00
|
|
|
>
|
2016-07-31 09:53:51 +08:00
|
|
|
<Checkbox {...getFieldProps('agreement', { initialValue: false, valuePropName: 'checked' })}>agree</Checkbox>
|
2015-10-29 08:41:51 +08:00
|
|
|
</FormItem>
|
2016-04-06 19:30:23 +08:00
|
|
|
<FormItem wrapperCol={{ span: 16, offset: 6 }} 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-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
|
|
|
````
|