Include `name` property in `onChange(selected)`
See original GitHub issueThis would make it easier to use a single onChange
handler for tracking current state.
e.g. The same change handler
const onChange = (selected) => {
this.setState({ [selected.name]: selected.value })
}
Could be used for
<Select
name="form-field-name-one"
value="one"
options={optionsForOne}
onChange={onChange}
/>
<Select
name="form-field-name-two"
value="two"
options={optionsForTwo}
onChange={onChange}
/>
My current workaround is to create a handler which uses a closure to track the name.
_createChangeHandler(name) {
const onChange = (newValue) => this.setState({ [name]: newValue.value });
return onChange;
}
const onChange = this._createChangeHandler(name);
return (
<Select
name={name}
value={this.state[name]}
onChange={onChange}
...
/>
);
but I’d prefer it be available from the function’s argument(s).
Issue Analytics
- State:
- Created 7 years ago
- Reactions:11
- Comments:11
Top Results From Across the Web
when using {react-select} Cannot read property 'name' of ...
The first argument is the selected option (or options if you have isMulti set). There is also a second argument which is an...
Read more >View or change the properties for an Office file
View or create custom properties for the current file · In the Name box, type a name for the custom property, or select...
Read more >SCR19: Using an onchange event on a select element ... - W3C
The objective of this technique is to demonstrate how to correctly use an onchange event with a select element to update other elements...
Read more >onchange Event - W3Schools
The onchange event occurs when the value of an element has been changed. For radiobuttons and checkboxes, the onchange event occurs when the...
Read more >Function.prototype.name - JavaScript - MDN Web Docs
To change it, use Object.defineProperty() . The name property is typically inferred from how the function is defined. In the following sections, ...
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
It seems weird that there’s no option to retrieve the name of the Select. How are people dealing with multiple Selects in forms? Multiple onChange functions…?
The fact this functionality hasn’t been implemented is enough for me to switch to a different solution, is there any hope this will change? Will pull-requests be accepted for it?