onChange returns the selected value, not the complete event
See original GitHub issueonChange simply returns the new value and label and not the whole event.
I understand we can use the hidden input field to fire an onChange but this does not happen automatically and while we can manually fire an onChange for hidden input field, we can also wrap an event around the Select. Here is how I am doing it following #520:
<Select
name="form-field-name"
value={val}
options={options}
onChange={(val)=> {onChangeFunc({target: { name:'revision_id', value: val.value }})}}
/>
Creating an object myself and passing it to my onChange handler. Is this the right way to do it or you can suggest a better way around it?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:96
- Comments:46 (3 by maintainers)
Top Results From Across the Web
OnChange event using React JS for drop down - Stack Overflow
The change event is triggered on the <select> element, not the <option> element. However, that's not the only problem.
Read more >Handle the onChange event on a Select element in React
To handle the onChange event on a select element in React, set the `onChange` prop on the select element. Keep the value of...
Read more >Advanced - React Select
React Select exposes a variety of eventListeners to you via props. The onchange function prop now has the following signature. (value: ValueType, action: ......
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 >react-select - npm
See react-select.com for live demos and comprehensive docs. ... return ( <Select value={selectedOption} onChange={this.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ashnur I’m going to address your comment for the benefit of anyone else who is seeking to understand the reasoning here, but I also want to make it clear that your language and tone is not welcome or acceptable.
First of all, this isn’t about retaining the synthetic event, I know how to do that - it’s about getting an event in the first place.
It’s not possible to create a
select
component and capture anonChange
event by changing itsvalue
. The event requires user interaction to fire. Faking the interaction would be significantly less predictable than choosing not to try and conform to an API that we can’t correctly implement.There. Isn’t. Such. An. Event. There is for native
select
components, and if they do what you need, I wouldn’t recommend using this library.react-select
is one giant non-standard workaround. It fills a gap left by the HTML spec, because native select controls are insufficient for a range of use cases; that hasn’t changed in two decades, and this is far from the first library to deal with it (prior art includes Selectize and Select2 for jQuery, you can go further back to YUI and other frameworks if you like)There’s no such thing as a “proper API”. This project is not pretending to be a native form control. If anything, the API has been designed to prevent implementation details (such as unpredictable source events) from leaking through.
Anyway, I’m done with this issue, hope the explanation and workaround helps people who come across this in the future, but I don’t maintain this project to be called dishonest or obnoxious.
@JedWatson