Skip to content
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

Multiselect not working #1308

Closed
reznord opened this issue Oct 15, 2016 · 12 comments
Closed

Multiselect not working #1308

reznord opened this issue Oct 15, 2016 · 12 comments

Comments

@reznord
Copy link

reznord commented Oct 15, 2016

@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 reznord closed this as completed Oct 16, 2016
@reznord reznord reopened this Oct 16, 2016
@reznord
Copy link
Author

reznord commented Oct 16, 2016

Still facing the same issue.

@digitalmio
Copy link

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

@KevinBrolly
Copy link

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

@reznord
Copy link
Author

reznord commented Oct 28, 2016

@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 reznord closed this as completed Oct 28, 2016
@arackaf
Copy link

arackaf commented Mar 21, 2017

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

@newswim
Copy link

newswim commented Jun 24, 2017

Would this PR resolve the issue?
#1600

@JarLowrey
Copy link

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.

@Kapil-Vermani
Copy link

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

@chevonc
Copy link

chevonc commented Nov 28, 2017

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

@externuz
Copy link

Same issue as @chevonc described

@fernandocvlopes
Copy link

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.

@k-vikram
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests