简体   繁体   中英

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?

<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 . How should I get the value of FieldName to set the value of FieldNameAlt ?

If I understand correctly, you can get the value of the changed field by simply using the event passed to the onChange :

onChange={e => {
    const val = e.target.value;
    this.props.change('FieldNameAlt', val)
}};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM