question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not selecting value if onChange is used

See original GitHub issue

So, my react-select component is not selecting the value. Here is my initialization code.

        <Select
          name="form-field-name"
          options={ areas }
          onChange={ this.areaSelected }
        />

This is the areaSelected.

  areaSelected: function(value) {
    AreaActions.setArea(value);
  },

The action update my state beautifully, but the select component do not updated. Is it a bug?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7

github_iconTop GitHub Comments

7reactions
brianreaviscommented, Jun 18, 2015

You need to set the value={currentValue} property.

0reactions
ghostcommented, Feb 14, 2017

Hi All 😃

Sorry to ask a question on a closed issue but I have got react-select working ok eventually with redux-form until I added an onChange…now despite following the advice given above (updating State and setting the value attribute) react-select still will not allow me to Select a value from the list when the onChange has been added.

Could it be that the suggested workaround is not compatible with redux-form? If I console.log the value of the “value” attribute it seems to get lost when I call the ReduxForm.Field component, stopping the above suggested workarounds from, well, working.

Has anyone else seen this?

Thanks again!

Update

For anyone who gets led here by Google I think I sorted it. To get redux-form and react-select to play together basically ensure that Select.onBlur, onChange and value end up calling/using input.onBlur, input.onChange and input.value

  const {input, onChange, [etc]  } = props
   
  <Select
     ...
     onBlur={() => {input.onBlur(input.value)}} // so react-select keeps its value in redux-form on blur
     onChange = { (e) =>  input.onChange(onChange(e))  } // put your own code in "onChange"
     value={input.value} // needed for onChange attr to work
      />

Still testing but this seems to work with

  • “redux-form”: “^6.2.0”
  • “react-select”: “^1.0.0-rc.2”
  • “webpack”: “^1.13.0”
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why am I not getting the value from onChange with Select?
i tried that first. Issue is my form is being created dynamically. Jquery would handle it only if my select box was static...
Read more >
SCR19: Using an onchange event on a select element ... - W3C
Navigate to the trigger select element, navigate through the options but do not change the value. Check that the matching option values are...
Read more >
HTMLElement: change event - Web APIs | MDN
When the user commits the change explicitly (e.g., by selecting a value from a <select> 's dropdown with a mouse click, by selecting...
Read more >
How to Use Option Selected Property in JavaScript - Tabnine
This approach has a problem – namely, if the user does not choose a different value, no change takes place. This means that...
Read more >
Javascript onchange Event Tutorial to Get Dropdown Value of ...
... code of application here:https://codingshiksha.com/javascript/javascript- onchange -event-tutorial-to-get-dropdown- value - of - select -inp...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found