You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.0 KiB

# 典型表单
10 years ago
- order: 2
10 years ago
9 years ago
示例展示了如何通过使用 `Form.create` 来获取和更新表单提交的数值。
9 years ago
10 years ago
---
````jsx
import { Form, Input, Button, Checkbox, Radio, Row, Col } from 'antd';
const FormItem = Form.Item;
const RadioGroup = Radio.Group;
9 years ago
let Demo = React.createClass({
handleSubmit(e) {
e.preventDefault();
9 years ago
console.log('收到表单值:', this.props.form.getFieldsValue());
},
render() {
9 years ago
const { getFieldProps } = this.props.form;
return (
<Form horizontal onSubmit={this.handleSubmit}>
<FormItem
label="用户名:"
labelCol={{ span: 6 }}
9 years ago
wrapperCol={{ span: 14 }}>
<p className="ant-form-text" id="userName" name="userName">大眼萌 minion</p>
</FormItem>
<FormItem
label="密码:"
labelCol={{ span: 6 }}
9 years ago
wrapperCol={{ span: 14 }}>
<Input type="password" {...getFieldProps('pass')} placeholder="请输入密码" />
</FormItem>
<FormItem
label="您的性别:"
labelCol={{ span: 6 }}
wrapperCol={{ span: 14 }}>
<RadioGroup {...getFieldProps('gender', { initialValue: 'female' })}>
<Radio value="male">男的</Radio>
<Radio value="female">女的</Radio>
</RadioGroup>
</FormItem>
<FormItem
label="备注:"
labelCol={{ span: 6 }}
wrapperCol={{ span: 14 }}
help="随便写点什么">
9 years ago
<Input type="textarea" placeholder="随便写" {...getFieldProps('remark')} />
</FormItem>
<FormItem
wrapperCol={{ span: 14, offset: 6 }}>
<label>
9 years ago
<Checkbox {...getFieldProps('agreement')} />同意
</label>
</FormItem>
<Row>
<Col span="16" offset="6">
<Button type="primary" htmlType="submit">确定</Button>
</Col>
</Row>
</Form>
);
}
});
9 years ago
Demo = Form.create()(Demo);
ReactDOM.render(<Demo />, mountNode);
10 years ago
````