Redux-form: How to get the new value in the onChange event object ?

Created on 5 Aug 2016  路  2Comments  路  Source: redux-form/redux-form

I want to override the onChange event.

  function handleCustomChange(event){
      //Do something
      //...
     // I get event.target.value in here. But I got a old value. It's same different from the pure js's event object. 
     this.props.field.userName.onChange(newValue);
  }

For example. The initial value of the userName field is Tom. the I input 'a'. The I got the 'Tom' from event.target.value and I expect it is 'Toma'.

So, How can I get the new value before I call redux-form's onChange handler?

Regards.

Most helpful comment

Are you using V5 or V6?

In V6 (RC3) I use the following:

<Field name="myField" component={props =>
  <select
    {...props}
    onChange={event => {
      console.log("This is the new value of field myField: " + event.target.value);
      props.input.onChange(event); // <-- Propagate the event
    }>
      {myDynamicallyGeneratedOptions}
    </select>
}/>

And it works fine.

All 2 comments

Are you using V5 or V6?

In V6 (RC3) I use the following:

<Field name="myField" component={props =>
  <select
    {...props}
    onChange={event => {
      console.log("This is the new value of field myField: " + event.target.value);
      props.input.onChange(event); // <-- Propagate the event
    }>
      {myDynamicallyGeneratedOptions}
    </select>
}/>

And it works fine.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings