chosen search for multiple words

3.6k views Asked by At

I'm using chosen (chosen website) and it lets the user search for United States by inputting "United", but If user wants to input "United States", the search doesn't seems to work.

What can I do in order to let user search for multiple words?

Here is the HTML code:

    <select data-placeholder="Séléctionnez une installation" id="installationDiffusion" multiple="multiple" name="installationDiffusion" class="chosen">
    <option value="15">Test -&gt; Machine 1</option>
    <option value="16">Test -&gt; Machine 2</option>
    <option value="17">Test -&gt; Machine 3</option>
    <option value="15">Test2 -&gt; Machine 1</option>
    <option value="16">Test2 -&gt; Machine 2</option>
    <option value="17">Test2 -&gt; Machine 3</option>
    </select>

    $$('.chosen').chosen({});

Here is the fiddle of this code: fiddle of issue

Here it is the result I want to have :

Search : Machine 1
Result: not found
2

There are 2 answers

0
clement On BEST ANSWER

answer is:

search_contains: true

For instance here

$("#mySelector").chosen({ width: "350px", search_contains: true });

will search into the whole phrase.

0
RWAM On

Ok, the plugin itself lacks on this problem. It works only with phrases started on the beginning of the value – try on the demo site to search after and T – no result ;(

There are some issues like https://github.com/harvesthq/chosen/issues/2127 or https://github.com/harvesthq/chosen/issues/75.

May you can try this open pull request on https://github.com/harvesthq/chosen/pull/1483

Sorry.