Get name of select component onChange
See original GitHub issueIs it possible to detect what select component triggered an onChange
event? Doesn’t look like it in the docs, but maybe there is a workaround?
Use case: I have several select components that are filtering a table, right now every select component needs its own handleChange
function triggered by OnChange
, but all I need is the name
to use as a key to make my updates.
e.g. would be nice to do something like:
constructor() {
this.state = {
branchFilter: '',
moduleFilter: ''
}
}
handleFilterChange(newValue, [selectedOptions], name) {
this.setState({
[name]: newVal
});
}
render() {
return (
<div className='branch-filter'>
<Select
name="branchFilter"
value={this.state.branchFilter}
options={uniqueBranches(this.props.branches)}
onChange={this.handleBranchFilterChange}
/>
<Select
name="moduleFilter"
value={this.state.moduleFilter}
options={uniqueModules(this.props.branches)}
onChange={this.handleModuleFilterChange}
/>
</div>
Issue Analytics
- State:
- Created 8 years ago
- Reactions:23
- Comments:21 (1 by maintainers)
Top Results From Across the Web
Get the name of the select with onchange event - Stack Overflow
It gives the name of select in console. function myfunction(Element) { console.log($(Element).
Read more >onchange Event - W3Schools
The onchange event occurs when the value of an element has been changed. ... The other difference is that the onchange event also...
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 >API - React Select
Get the styles of a particular part of the select. Pass in the name of the property as the first argument, and the...
Read more >HTMLElement: change event - Web APIs | MDN
The change event is fired for <input> , <select> , and <textarea> elements when the user modifies the element's value.
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
The following code works for me
and this one for a .map() iterator
The first thing that a user will encounter most often is stuck on this issue!