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

Multiselect not working

Open reznord opened this issue 10 years ago • 12 comments

@JedWatson I am trying to implement a multi-select dropdown in my app using react-select. The problem what I am facing is when I add the multi={true} flag, the values are not being selected from the options in the dropdown list.

It has the same problem in one of your examples on the website, the numeric-values example with multi-select enabled.

I am attaching the code for my dropdown here, please tell me if I am going wrong anywhere:

Dropdown.jsx


 import React, { Component, PropTypes } from 'react';
 import styles from './styles/dropdown.css';
 import config from './styles/config.css';
 import Select from 'react-select';
 import compose from 'lodash.compose';
 import { makeHorizontalComponent, makeVerticalComponent } from './utils';
 import cssModules from 'react-css-modules';

 @cssModules({ ...styles, ...config })
 class Dropdown extends Component {
    static defaultProps = {
        orientation: 'horizontal'
    }
    constructor(props) {
        super(props);
    }

    render() {
        const { onBlur, label, multiple,
                upload, description,
                options, className,
                labelKey, valueKey,
                orientation, popup,
                input: { onChange, value, onBlur: reduxOnBlur, name }
        } = this.props;

        const composedOnBlur = compose(reduxOnBlur, onBlur ? onBlur : f => f);

            <Select multi simpleValue value={value} clearable={false} options={options} labelKey={labelKey} valueKey={valueKey} placeholder="Select the days"onBlur={() => composedOnBlur(value, name)} onChange={ (object) => onChange(object[valueKey] || object.value) } />

and I am using this Dropdown component as follows:

const days = [
    {id: 1, label: 'Sun'},
    {id: 2, label: 'Mon'},
    {id: 3, label: 'Tue'},
    {id: 4, label: 'Wed'},
    {id: 5, label: 'Thu'},
    {id: 6, label: 'Fri'},
    {id: 7, label: 'Sat'},
];

<Field component={Dropdown}
    label="Days"
    popup={true}
        options={days}
        multiple={true}
    valueKey="id"
    labelKey="label"
    name="autoDial.workingDays"
    className="row-popup"
    description="System Management is privilege can allow anyone to alter lorem ispum"
/>

When i try to select a value from the dropdown, it doesn't even get selected.

reznord avatar Oct 15 '16 19:10 reznord

Still facing the same issue.

reznord avatar Oct 16 '16 06:10 reznord

FYI - had the same problem. Temporarily fixed by downgrading to 0.9.1.

digitalmio avatar Oct 18 '16 18:10 digitalmio

I am also having this problem on 1.0.0, going back to 0.9.1 fixed it for me as well.

KevinBrolly avatar Oct 26 '16 08:10 KevinBrolly

@digitalmio @KevinBrolly it works for me now, It was my mistake earlier. This is the code which I used and it works perfectly fine for me.

@JedWatson sorry for opening this issue. It was my mistake earlier. Closing this issue.

import React, {PropTypes, Component} from 'react';
import Select from 'react-select';

const fruits = [
    { label: 'Banana', value: '1' },
    { label: 'Apple', value: '2' },
    { label: 'Mango', value: '3' },
    { label: 'Goa', value: '4' },
    { label: 'Grapes', value: '5' },
    { label: 'Pine Apple', value: '6' },
];

export default class MultiSelectField extends Component {
  constructor(props) {
    super(props);
    this.state = {
      crazy: false,
      value: [],
    };
    this.handleSelectChange = this.handleSelectChange.bind(this);
  }

  handleSelectChange(value) {
    console.log('You have selected: ', value);
    this.setState({ value });
  }

  static propTypes = {
    label: PropTypes.oneOfType([
      PropTypes.string,
      PropTypes.array,
      PropTypes.object,
    ])
  }

  render () {
        return (
            <div className="section">
                <h3 className="section-heading">{this.props.label}</h3>
                <Select multi joinValues value={this.state.value} placeholder="Select your favourite(s)" options={fruits} onChange={this.handleSelectChange} />
            </div>
        );
    }
}

reznord avatar Oct 28 '16 16:10 reznord

Ugh - so to sum up, and to hopefully help out whoever shows up here from Google, you need to manually manage the value to the Select component - pass in the array of selected values, and add to it in onChange

arackaf avatar Mar 21 '17 04:03 arackaf

Would this PR resolve the issue? https://github.com/JedWatson/react-select/pull/1600

newswim avatar Jun 24 '17 23:06 newswim

To summarize even further than @arackaf , the important parts of @reznord 's code block is 1)passing this.state.value as Select's value, and the onChange callback that adds to the state's value array when the user selects it.

JarLowrey avatar Nov 13 '17 19:11 JarLowrey

react-select (1.0.0) in multi mode is not working in latest version of chrome

Kapil-Vermani avatar Nov 21 '17 08:11 Kapil-Vermani

Yeah, I am seeing a similar issue where the multi select menu will not open after selecting the first value. Any thoughts?

chevonc avatar Nov 28 '17 19:11 chevonc

Same issue as @chevonc described

externuz avatar Dec 25 '17 11:12 externuz

Maybe it can help someone... I just forgot to import the CSS at the beginning, after that it worked properly: import 'react-select/dist/react-select.css';

By the way, it is in the docs on "Installation" although it is not in the "multiselect" exemple page.

fernandocvlopes avatar Mar 22 '18 17:03 fernandocvlopes

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 what I am missing here?

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