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

Error with searching value in options #4174

Closed
chandra10207 opened this issue Aug 22, 2020 · 3 comments
Closed

Error with searching value in options #4174

chandra10207 opened this issue Aug 22, 2020 · 3 comments
Labels
issue/reviewed Issue has recently been reviewed (mid-2020)

Comments

@chandra10207
Copy link

Error while searching a value in options

For eg.

If my options contain the label "Red face and eyes". while searching on the field, if user type "red face", an option with "Red face and eyes" appears. However, If the user input is "red eyes" then it shows no options.

Is there any option to search options by word or similar solution for my case?

My Code is,

const options = [
  { value: '0', label: 'Red face and eyes' },
  { value: '1', label: 'Dark red nose and lips' },
]

<Select
          name="symptoms-search"
          placeholder="Click here to search"
          value={this.state.query}
          components={animatedComponents}
          options={options}
          onChange={this.handleMultiChange}
          isMulti
          isSearchable
        />

Thank you.

@bladey bladey added category/question issue/reviewed Issue has recently been reviewed (mid-2020) labels Aug 24, 2020
@ebonow
Copy link
Collaborator

ebonow commented Aug 24, 2020

Greetings,

This page explains a bit more about the filterOption prop and createFilter method, but here would be a crude implementation to get you started.

  const filterOption = (option, input='') => {
    const label = option.label.toLowerCase();
    return input.toLowerCase().split().every(word => label.includes(word));
  }

<Select filterOptions={filterOption} ... />

Let me know if this helps and please close this issue if it does.

@chandra10207
Copy link
Author

chandra10207 commented Sep 3, 2020

HI @ebonow,
I tried but still not working.

My Code.

 const filterOption = (option, input='') => {
    const label = option.label.toLowerCase();
    console.log("inside filter");
    return input.toLowerCase().split().every(word => label.includes(word));
  }

    return (
      
          <Select
          name="symptoms-search"
          placeholder="Click here to select symptoms"
          // value={this.state.querySymptoms}
          value={selected}
          // options={this.state.filterOptions}
          components={animatedComponents}
          options={options}
          onChange={this.handleMultiChange}
          isMulti
          isSearchable
          noOptionsMessage={inputValue => 'No symptoms found'}
          filterOptions={filterOption}
        />
      </div>
    );

@chandra10207
Copy link
Author

Thanks guys.

This works for me.

#3067

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue/reviewed Issue has recently been reviewed (mid-2020)
Projects
None yet
Development

No branches or pull requests

3 participants