const { getFieldDecorator } = this.props.form;
this.getFieldsValue = this.props.form.getFieldsValue;//获得表单所有控件的值
this.props.form.getFieldsValue(“name”)//获得指定控件的值
this.props.form.validateFields((err, values) => {}) //校验并获取一组输入域的值与 Error,若 fieldNames 参数为空,则校验全部组件
在ant design 2x 中
{getFieldDecorator('note', { rules: [{ required: true, message: 'Please input your note!' }], })( <Input />)
getFieldDecorator 用于和表单进行双向绑定,其中
经过 getFieldDecorator
包装的控件,表单控件会自动添加 value,
数据同步将被 Form 接管
{
title: '付款金额',
dataIndex: 'needPayPrice',
key: 'needPayPrice',
width: 120,
render: (text, record, index) => {
return (<FormItem style={{ marginBottom: 0 }}>{this.getFieldDecorator(`needPayPrice_${index}`, {
initialValue: record.no_pay_amount,
rules: [
{
message: '请填写正确的付款金额',
pattern: /(^[0-9]{1,9}$)|(^[0-9]{1,9}[.]{1}[0-9]{1,2}$)/,
required: true,
},
{
validator: (rule, value, callback) => {
if (Number(value) <= 0) {
callback('请填写正确的付款金额');
}
callback();
},
},
],
validateFirst: true,
})(<Input placeholder="付款金额" style={{ width: 80 }} />)}
</FormItem>);
},
},