react-select icon indicating copy to clipboard operation
react-select copied to clipboard

Multiselect not selecting a value

Open SoorajChandran opened this issue 8 years ago • 11 comments

I use the following code to create a select which works fine.

                 <Select
                    name="form-field-name"
                    
                    value={this.state.selectedOption.value}
                    onChange={this.handleChange}
                    options={[
                      { value: 'one', label: 'One' },
                      { value: 'two', label: 'Two' },
                    ]}
                  />

But when I add a mulit={true} to this, it doesn't work. Even when I select a value it shows undefined. Am I doing something wrong?

SoorajChandran avatar Dec 08 '17 18:12 SoorajChandran

Yeah, I had the same issue, what I ended out doing was having an inline onChange function. I used something like this: onChange={event => onChange(event.value)}; I would try to add debugger; to your code, and step through it. What you should be looking for is where the selected value gets set. The fact its not being set, tells me that you are not actually getting the select's actual value.

garrettdehnketurpin avatar Dec 12 '17 14:12 garrettdehnketurpin

I solved this using below code:

            <Select
              name="form-field-name"
              value={this.state && this.state.techFilter}
              multi
              placeholder="Filter by language/framework"
              onChange={(...args) => this.handleChange(...args)}
              options={[
                { value: "reactjs", label: "ReactJs" },
                { value: "css", label: "CSS" },
                { value: "es6", label: "ES6" },
                { value: "nodejs", label: "Node" }
              ]}
            />
 handleChange = selectedOptions => {
    this.setState({ techFilter: selectedOptions });
  };

SoorajChandran avatar Dec 14 '17 06:12 SoorajChandran

thanks @SoorajChandran :boom:

laryssamagalhaes avatar Feb 20 '18 13:02 laryssamagalhaes

Is this a bug or is this how we correctly implement multi?

1-800-jono avatar Mar 05 '18 20:03 1-800-jono

Going to 1+ this. I rolled back to "react-select": "1.0.0-rc.10" and multi works in that version. Was using 1.2.1 before.

Joebob12 avatar Apr 06 '18 14:04 Joebob12

for any poor soul that follows the docs on the official site that says 'isMulti' change this to 'multi'.

ktranel avatar Jul 31 '18 20:07 ktranel

So, for me it was adding some additional flags to the select: onBlurResetsInput, onSelectResetsInput, onCloseResetsInput. Hope this helps someone :)

<Select
      multi
      placeholder="Search..."
      onBlurResetsInput={false}
      onSelectResetsInput={false}
      onCloseResetsInput={false}
      onChange={this.onChange}
      options={options}
      value={selected}
/> 

gabmichels avatar Aug 20 '18 17:08 gabmichels

It works for me but if you see docs

isMulti - allow the user to select multiple values

but I had to use multi={true} to make it work for multiple values.

Can anybody tell did I miss reading in-between the lines?

k-vikram avatar Nov 12 '19 14:11 k-vikram

@k-vikram It´s due to version differences.

v1.x uses the prop under the name multi, which can be seen in the GitHub documentation for v1.x.

v2.x and above uses the name isMulti for the prop to manage multiple selection, which is documented in the official docs.

(Also, please don´t ask the same question multiple times in different issues (even closed ones) (#1308))

Rall3n avatar Nov 12 '19 17:11 Rall3n

Ya, figured that out but forgot to update here, many thanks.

k-vikram avatar Nov 17 '19 04:11 k-vikram

Hi all,

Thank you @Rall3n and everyone else who had a part in addressing this question.

This is now documented correctly for v2 and above.

However, if you feel this issue is still relevant and you'd like us to review it, or have any suggestions regarding this going forward - please leave a comment and we'll do our best to get back to you!

bladey avatar Jun 17 '20 02:06 bladey