From 83769f27b5656b45db91430b26132f13768b8176 Mon Sep 17 00:00:00 2001 From: Paul Naumov Date: Fri, 17 Mar 2017 00:09:10 +0300 Subject: [PATCH 1/3] Update abstract-chosen.coffee --- coffee/lib/abstract-chosen.coffee | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/coffee/lib/abstract-chosen.coffee b/coffee/lib/abstract-chosen.coffee index f6f337ed5eb..a02a68273f0 100644 --- a/coffee/lib/abstract-chosen.coffee +++ b/coffee/lib/abstract-chosen.coffee @@ -26,6 +26,7 @@ class AbstractChosen @disable_search = @options.disable_search || false @enable_split_word_search = if @options.enable_split_word_search? then @options.enable_split_word_search else true @group_search = if @options.group_search? then @options.group_search else true + @search_in_values = @options.search_in_values || false @search_contains = @options.search_contains || false @single_backstroke_delete = if @options.single_backstroke_delete? then @options.single_backstroke_delete else true @max_selected_options = @options.max_selected_options || Infinity @@ -165,6 +166,7 @@ class AbstractChosen results = 0 searchText = this.get_search_text() + searchMatchFromValue = null escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") regex = this.get_search_regex(escapedSearchText) highlightRegex = this.get_highlight_regex(escapedSearchText) @@ -189,10 +191,15 @@ class AbstractChosen unless option.group and not @group_search option.search_match = this.search_string_match(option.search_text, regex) + + if !option.search_match and @search_in_values + option.search_match = this.search_string_match(option.value, regex) + searchMatchFromValue = true + results += 1 if option.search_match and not option.group if option.search_match - if searchText.length + if searchText.length and !searchMatchFromValue startpos = option.search_text.search highlightRegex text = option.search_text.substr(0, startpos + searchText.length) + '' + option.search_text.substr(startpos + searchText.length) option.search_text = text.substr(0, startpos) + '' + text.substr(startpos) From 9cde3c42ac8dadde530446e20c49294045ef704c Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 17 Mar 2017 01:22:35 +0300 Subject: [PATCH 2/3] New "search_in_values" option, which allows you to perform search in "value" attribute of the ' + option.search_text.substr(startpos + searchText.length) option.search_text = text.substr(0, startpos) + '' + text.substr(startpos) From 2338e90af069fd2c44660199ac7b94ddde42cfd4 Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 17 Mar 2017 01:34:01 +0300 Subject: [PATCH 3/3] Description of the new 'search_in_values' option --- public/options.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/public/options.html b/public/options.html index c64d5a6747f..45d4aa9f424 100644 --- a/public/options.html +++ b/public/options.html @@ -86,6 +86,11 @@

Example:

false By default, Chosen’s search matches starting at the beginning of a word. Setting this option to true allows matches starting from anywhere within a word. This is especially useful for options that include a lot of special characters or phrases in ()s and []s. + + search_in_values + false + By default, Chosen’s search matches in content of HTML<option> element. Setting this option to true allows matches in value attribute of the <option> element. + single_backstroke_delete true