Hello!
Could I set max number of selected options for multi select?
Thanks!
It would be nice to have it built in, but it is also easy to do by yourself:
For example:
let newOptions = this.state.currentOptions;
if (this.state.selected != null && this.state.selected.length === MAX) {
newOptions = [];
}
return (
<Select
multi
value={this.state.selected}
options={newOptions}/>
);
@caiolopes That method doesn't quite work. Upon hitting MAX, the options already selected disappear ostensibly because the values in the array passed to the value prop are no longer founder in options.
Please disregard, I had been passing in an array of strings, e.g. ["apple", "banana"] for the value property.
I was not aware I could also pass in [{label: "Apple", value: "apple"}, {label: "Banana", value: "banana"}]. Of course that is perfectly reasonable sense that's the format returned in onChange :)
Hello -
In an effort to sustain the react-select project going forward, we're closing old issues / pull requests.
We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our limited efforts to maintain the latest version.
If you aren't using the latest version of react-select please consider upgrading to see if it resolves any issues you're having.
If you feel this issue / pull request is still relevant and you'd like us to review it, please leave a comment and we'll do our best to get back to you.
Most helpful comment
It would be nice to have it built in, but it is also easy to do by yourself:
For example: