-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include name
property in onChange(selected)
#1458
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...? |
This is the only nagging issue I have with this library. It seems like since the |
I hate half-assing comments when I'm asking for things, so here's more concreted example that would make my project a lot cleaner: handleChange = (selectedItem, nameOfComponent) => {
// do things
}
render() {
return (
<React.Fragment>
<ReactSelect
name='firstSelect'
value={something}
onChange={this.handleChange}
options={someOptions} />
<ReactSelect
name='otherSelectName'
value={otherSmething}
onChange={this.handleChange}
options={otherOptions} />
</React.Fragment>
);
} |
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? |
https://react-select.com/upgrade-guide |
@markoj3s right. Example (insert your option and check the console ) :
|
Looks like the second argument of the onChange event only includes the name if there is one option selected, not when isMulti is enabled and you have more than one item selected or you are creating a new item with a CreatableSelect. |
+1 The same should apply to
|
+1 Not having an event.target on the onChange option makes this component much less usable in my opinion. |
I've started a fork of react-select. Feel free to resubmit this issue on the fork and/or submit a PR to resolve this issue on the fork and we can get it merged and released. |
Greetings @codenamerhubarb I was not able to reproduce. It appears in all cases onChange was returning the name in the context parameter regardless of value, no value, isMulti, or creating new option. Here is my testing codesandbox |
This would make it easier to use a single
onChange
handler for tracking current state.e.g. The same change handler
Could be used for
My current workaround is to create a handler which uses a closure to track the name.
but I'd prefer it be available from the function's argument(s).
The text was updated successfully, but these errors were encountered: