Saswat Saswat - 5 months ago 17
jQuery Question

Search issue on chosen dropdown using jQuery

I am implementing chosen dropdown in my project. But I have some problem which I want to solve.

Before proceeding, let me give you the jQuery fiddle:

http://jsfiddle.net/jHvmg/278/

Now I have a dropdown like this

<select id="drp_menu">
<option value="Option 1">Option 1</option>
<option value="Option 2">Option 2</option>
<option value="Option 3">Option 3</option>
<option value="Option 4">Option 4</option>
<option value="Option 5">Option 5</option>
</select>


As you can see in the fiddle:

1) If I write
"Opt"
in the searchbox then the list is filtered showing all the options.

2) If I write
" 1"
it shows
"Option 1"


3) If I write
"1"
it shows
"Option 1"


4) If I write
"ptio"
then it states
"No results"


5) If I write
"tio"
then it states
"No result"


I want to results if words typed in the searchbox matches.

Answer

add { search_contains: true } and Enjoy :)

JS Code:

$(document).ready(function()
{
   $('#drp_menu').chosen({ search_contains: true });                      
});

Demo

Comments