[英]Validation for Rate component ant.design
I'm trying to validate Rate component, set initial value, etc.我正在尝试验证 Rate 组件、设置初始值等。
{getFieldDecorator('rating', {
initialValue: dataSource.getIn(['data', 'rating'], ''),
rules: [{ required: true, message: 'Field is required' }],
})(<Rate allowClear={false} onChange={this.setRating} />)}
Having code like this in my form result in an error after each value change在我的表单中有这样的代码会在每次值更改后导致错误
Warning:
getFieldDecorator
will overridevalue
, so please don't setvalue
directly and usesetFieldsValue
to set it.警告:
getFieldDecorator
会覆盖value
,所以请不要直接设置value
并使用setFieldsValue
来设置它。
Any ideas how to overcome it?任何想法如何克服它? Code works as expected
代码按预期工作
I think the reason is because you should not use onChange
when your component is being controlled by the Form
我认为原因是因为当你的组件被
Form
控制时你不应该使用onChange
if you would want to get the actual rate using: this.props.form.validateFields()
since will be also do the field validation如果您想使用以下
this.props.form.validateFields()
获得实际费率: this.props.form.validateFields()
因为也将进行字段验证
To validate <Rate />
in antd design
you should use null
as initial value.要在
antd design
验证<Rate />
,您应该使用null
作为初始值。
<Form.Item>
{getFieldDecorator('rating', {
initialValue: review.rating ? review.rating:null,
rules: [
{
required: true,
message:'Rating Required',
},
],
})(
<Rate />,
)}
</Form.Item>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.