[ACCEPTED]-Changing search behavior in jquery plugin Chosen-jquery-plugins
As mentionned in some more recent answers, the 9 plugin now implemements an option to change 8 the search behavior:
search_contains: true
The plugin does not 7 provide an option to change the search method 6 behavior.
If you're willing to change the 5 plugin source itself, here's a way to do 4 it.
The method that makes the search in the 3 plugin is Chosen.prototype.winnow_results
. It uses a regular expression 2 that matches text that "starts with" the 1 search term:
// "^": means "starts with"
// "searchText" is the text in the search input (it is just cleaned up don't be scared)
regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
Change it to:
regex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
The search behavior can be set with the 3 option search_contains
This is by default false
Set it to true
, and 2 chosen will also find matches inside instead 1 of only the beginning:
$('#my_dropdown').chosen({ search_contains: true });
As in Chosen 1.0, just add option {search_contains: true}
$('.selector').chosen({search_contains: true});
Have 1 fun.
in chosen 1.0 i did on line 301&302
escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
regexAnchor = "";
0
There is option search_contains
available to search sub-string 1 in options and can be used as:
$(".chosen-select").chosen({
search_contains: true
});
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.