Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Is there a way to limit number of selections? #62

Description

@pankajsoni19
No description provided.

Activity

  1. liamdiprose commented on Feb 20, 2020

    @liamdiprose

    In your onSelectedChanged handler function, you can decide whether to update the state object or not:

    const maxSelected = 3;
    const { options, selected } = this.state;
    <MultiSelect
          options={options}
          selected={selected}
          onSelectedChanged={(newSelected) => {
              if (newSelected.length <= maxSelected) {
                  // Number of Selections is OK, save to state...
                  this.setState({selected: newSelected})
              } else {
                  console.log("Too many selected");
              }
           }}
       />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions