question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiselect not working

See original GitHub issue

@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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:12

github_iconTop GitHub Comments

12reactions
arackafcommented, 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

9reactions
reznordcommented, 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>
        );
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Bootstrap Multiselect not working - Stack Overflow
I'm trying to use multiselect Bootstrap, I used the following code which is also available in their website too at (http://davidstutz.github.io/bootstrap- ...
Read more >
Bootstrap multiselect dropdown not opening in Bootstrap v5
This problem occurs since bs5 has changed all bootstrap "data-" attributes to "data-bs-". You can fix this directly in the js (also in...
Read more >
Checkbox multi-select not working - Laracasts
I'm using the Bootstrap plug-in to do the checkbox multi-select, but for some reason I'm not getting the multi check-boxes. Any ideas as...
Read more >
Multiselect not working for jquery/bootstrap
Expected behaviorhttps://mdbootstrap.com/docs/jquery/forms/multiselect/#basic-exampleActual behavior*it only displays options on screen.
Read more >
Bootstrap multiselect not working - MSDN
I am trying to use a dropdownlist with checkboxes instead of a multiselect list (default for <select multiple="multiple">).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found