Fez Vrasta
Fez Vrasta

Reputation: 14835

Chosen: search from begin of string

I'm using jQuery Chosen plugin to improve my select box, this is an example of the data:

Foobar Oooa
Ooafas Oob
Boombox Oooc

If I write in the search field of the selectbox oo it matches all the 3 elements, instead I'd like to match just the one which starts with oo.

I've tried with enable_split_word_search but seems to do nothing... Any idea? Thanks

Upvotes: 0

Views: 1745

Answers (2)

EyeSpy
EyeSpy

Reputation: 215

ok i finally figured it out after a while of try and error :D

you have more than one word in the options, and the plugin searches for the input at the start of every word, so even if you set search_contains to false, the second word in each option (Oooa, Oob and Oooc) matches. To disable this behaviour, you have to add "enable_split_word_search": false (as you already mentioned)

$(".test").chosen({
    search_contains: false,
    enable_split_word_search: false
});

if that doesn't work you probably don't have the latest version of chosen

here is a working fiddle: http://jsfiddle.net/UjCr7/4/

i tried different versions of the plugin and it didn't work with all of them, so if you want to use the version i have, just download v1.1.0 from https://github.com/harvesthq/chosen/releases

Upvotes: 2

EyeSpy
EyeSpy

Reputation: 215

you have to set the property

search_contains: false

if you set it to true it means, that it doesn't matter where the searched string is in the result, but if it is false, the searched text has to be in the beginning

Upvotes: 0

Related Questions