Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CHOSEN JQuery plugin, does anyone know if it can be made to do a 'contains' search?

I finally got this plugin to work with IE9 in compatibility mode only to realize that its only filtering by 'starts with' ... has anyone implemented or knows how to make this thing work with a 'contains' search instead?

like image 331
Todd Vance Avatar asked Mar 01 '12 19:03

Todd Vance


People also ask

What is chosen in jQuery?

Chosen is a JavaScript plugin that makes long, unwieldy select boxes much more user-friendly. It is currently available in both jQuery and Prototype flavors.


2 Answers

Chosen now supports this directly as an option:

$(".chzn-select").chosen({ search_contains: true });
like image 126
Jeff Miller Avatar answered Oct 16 '22 14:10

Jeff Miller


From 'pfiller' on the Chosen issues forum:

Chosen doesn't support it by default, but it is a relatively minor change. Just remove the ^ from the following line:

regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')

Should look like this now:

regex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
like image 23
Todd Vance Avatar answered Oct 16 '22 12:10

Todd Vance