[英]React redux-form get value of field to set other field
How can I get the value of one field so that onChange I can set the value of a different field with redux-form in react? 如何获取一个字段的值,以便onChange可以在react中使用redux-form设置另一个字段的值?
<Field
fullWidth
name="FieldName"
component={renderTextField}
label="FieldLabel"
onChange={this.props.change('FieldNameAlt', 9999)}
/>
Instead of 9999, say I wanted it to be the value of FieldName*2
. 而不是9999,请说我希望它是
FieldName*2
的值。 How should I get the value of FieldName
to set the value of FieldNameAlt
? 我应该怎么得到的值
FieldName
设置的值FieldNameAlt
?
If I understand correctly, you can get the value of the changed field by simply using the event
passed to the onChange
: 如果我理解正确,则只需使用传递给
onChange
的event
即可获取已更改字段的值:
onChange={e => {
const val = e.target.value;
this.props.change('FieldNameAlt', val)
}};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.