Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Multi-Select Dropdown in react-bootstrap

I am using react-bootstrap library. This library having a module called DropdownButton. So i am able to display data in dropdown. This is single selection data.

  <DropdownButton
            bsStyle="success"
            title={this.state.addLeadStageSelectTitle}
            key={"addleadstageDropDown"}
            id={"addleadstageIDAdd"}
            onSelect={this.handleSelectLeadStageAdd}
            >
                {this.state.vtx_sales_lead_status.map(objs => {
                   return (
                     <MenuItem eventKey={objs.id}>{objs.name}</MenuItem>
                  )

                }
                  )}
          </DropdownButton> 

But I am trying to create it multiselect with same library.

like image 691
Sucbe Sys Avatar asked Feb 07 '19 12:02

Sucbe Sys


People also ask

How set multiple values in React select?

The first and foremost thing we need to do is change the select element and make it let use select multiple values. The second thing we need to change is the constructor method and add an array so that we can use that array to store multiple selections from the user.


2 Answers

I've checked the react-bootstrap documentation and it looks like there isn't a multiselect functionality.

So you can use a third party library, like: react-bootstrap-multiselect.

It's a Multiselect component for React (with Bootstrap). This is a React wrapper around an existing jQuery / Bootstrap library: bootstrap-multiselect

Basic usage:

import Multiselect from 'react-bootstrap-multiselect'

const data = [{ value:'One', selected:true }, { value: 'Two' }, { value:'Three' }]

const App = props => {
  return <Multiselect onChange={props.handleChange} data={data} multiple />
}

Demo.

like image 70
Jordan Enev Avatar answered Sep 25 '22 15:09

Jordan Enev


It is supported now:

import { Form } from 'react-bootstrap';

// [...]

<Form>
  <Form.Control as="select" multiple value={options} onChange={onSelectedOptionsChange}>
    {options.map(options => (
      <option key={option.name} value={option.value}>
        {option.name}
      </option>
    ))}
  </Form.Control>
</Form>
like image 34
Knut Holm Avatar answered Sep 23 '22 15:09

Knut Holm