Search code examples
javascriptjqueryjquery-chosendropdownbox

Strange behavior in dropdown search, when using jquery plugin Chosen for dropdowns


Consider my fiddle here: http://jsfiddle.net/DFhAj/2/
I'm using the popular jquery plugin Chosen.

I have a select dropdown that looks like this:

<select>
    <option>Store North - New York, NY</option>
    <option>Store South - San Antonio, TX</option>
    <option>Store South #2 - San Antonio, TX</option>
    <option>Store East - Miami, FL</option>
</select>

When I click the dropdown and search for "store south", the 2 results correctly show. However, when I search for "san antonio", I get no results? It seems any search string that contains a space and appears after a dash doesn't work.

Any ideas what's going on?


Solution

  • You just need to add search_contains: true:

    $('select').chosen({
        search_contains: true
    }); 
    

    You can read more on the docs here.

    Updated Fiddle