Skip to content

Commit

Permalink
Allow search_optgroup to be disabled
Browse files Browse the repository at this point in the history
Searching the optgroup is enabled by default but can be disabled
setting search_optgroup option to false.
  • Loading branch information
chrisirhc committed Feb 28, 2013
1 parent 8be78eb commit 8273084
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 26 deletions.
15 changes: 9 additions & 6 deletions chosen/chosen.jquery.js
Expand Up @@ -135,6 +135,7 @@ Copyright (c) 2011 by Harvest
this.disable_search = this.options.disable_search || false;
this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true;
this.search_contains = this.options.search_contains || false;
this.search_optgroup = this.options.search_optgroup != null ? this.options.search_optgroup : true;
this.choices = 0;
this.single_backstroke_delete = this.options.single_backstroke_delete || false;
this.max_selected_options = this.options.max_selected_options || Infinity;
Expand Down Expand Up @@ -880,11 +881,13 @@ Copyright (c) 2011 by Harvest
if (!option.disabled && !option.empty) {
if (option.group) {
$('#' + option.dom_id).css('display', 'none');
option.search_match = this.winnow_search_match(regex, option.label);
text = searchText.length && option.search_match ? this.winnow_search_highlight_match(zregex, option.label, searchText.length) : option.label;
$('#' + option.dom_id).html(text);
if (option.search_match) {
results += 1;
if (this.search_optgroup) {
option.search_match = this.winnow_search_match(regex, option.label);
text = searchText.length && option.search_match ? this.winnow_search_highlight_match(zregex, option.label, searchText.length) : option.label;
$('#' + option.dom_id).html(text);
if (option.search_match) {
results += 1;
}
}
} else if (!(this.is_multiple && option.selected)) {
found = this.winnow_search_match(regex, option.html);
Expand All @@ -893,7 +896,7 @@ Copyright (c) 2011 by Harvest
}
result_id = option.dom_id;
result = $("#" + result_id);
if (found || ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match)) {
if (found || (this.search_optgroup && (option.group_array_index != null) && this.results_data[option.group_array_index].search_match)) {
if (searchText.length && found) {
text = this.winnow_search_highlight_match(zregex, option.html, searchText.length);
} else {
Expand Down
2 changes: 1 addition & 1 deletion chosen/chosen.jquery.min.js

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions chosen/chosen.proto.js
Expand Up @@ -135,6 +135,7 @@ Copyright (c) 2011 by Harvest
this.disable_search = this.options.disable_search || false;
this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true;
this.search_contains = this.options.search_contains || false;
this.search_optgroup = this.options.search_optgroup != null ? this.options.search_optgroup : true;
this.choices = 0;
this.single_backstroke_delete = this.options.single_backstroke_delete || false;
this.max_selected_options = this.options.max_selected_options || Infinity;
Expand Down Expand Up @@ -867,19 +868,21 @@ Copyright (c) 2011 by Harvest
if (!option.disabled && !option.empty) {
if (option.group) {
$(option.dom_id).hide();
option.search_match = this.winnow_search_match(regex, option.label);
text = searchText.length && option.search_match ? this.winnow_search_highlight_match(zregex, option.label, searchText.length) : option.label;
$(option.dom_id).update(text);
if (option.search_match) {
results += 1;
if (this.search_optgroup) {
option.search_match = this.winnow_search_match(regex, option.label);
text = searchText.length && option.search_match ? this.winnow_search_highlight_match(zregex, option.label, searchText.length) : option.label;
$(option.dom_id).update(text);
if (option.search_match) {
results += 1;
}
}
} else if (!(this.is_multiple && option.selected)) {
found = this.winnow_search_match(regex, option.html);
if (found) {
results += 1;
}
result_id = option.dom_id;
if (found || ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match)) {
if (found || (this.search_optgroup && (option.group_array_index != null) && this.results_data[option.group_array_index].search_match)) {
if (searchText.length && found) {
text = this.winnow_search_highlight_match(zregex, option.html, searchText.length);
} else {
Expand Down
2 changes: 1 addition & 1 deletion chosen/chosen.proto.min.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions coffee/chosen.jquery.coffee
Expand Up @@ -424,20 +424,20 @@ class Chosen extends AbstractChosen
if not option.disabled and not option.empty
if option.group
$('#' + option.dom_id).css('display', 'none')
if @search_optgroup
option.search_match = this.winnow_search_match(regex, option.label)
text = if searchText.length and option.search_match then this.winnow_search_highlight_match(zregex, option.label, searchText.length) else option.label

option.search_match = this.winnow_search_match(regex, option.label)
text = if searchText.length and option.search_match then this.winnow_search_highlight_match(zregex, option.label, searchText.length) else option.label

$('#' + option.dom_id).html(text)
if option.search_match
results += 1
$('#' + option.dom_id).html(text)
if option.search_match
results += 1
else if not (@is_multiple and option.selected)
found = this.winnow_search_match(regex, option.html)
results += 1 if found
result_id = option.dom_id
result = $("#" + result_id)

if found or (option.group_array_index? && @results_data[option.group_array_index].search_match)
if found or (@search_optgroup && option.group_array_index? && @results_data[option.group_array_index].search_match)
if searchText.length and found
text = this.winnow_search_highlight_match(zregex, option.html, searchText.length)
else
Expand Down
11 changes: 6 additions & 5 deletions coffee/chosen.proto.coffee
Expand Up @@ -402,18 +402,19 @@ class Chosen extends AbstractChosen
if option.group
$(option.dom_id).hide()

option.search_match = this.winnow_search_match(regex, option.label)
if @search_optgroup
option.search_match = this.winnow_search_match(regex, option.label)

text = if searchText.length and option.search_match then this.winnow_search_highlight_match(zregex, option.label, searchText.length) else option.label
$(option.dom_id).update(text)
results += 1 if option.search_match
text = if searchText.length and option.search_match then this.winnow_search_highlight_match(zregex, option.label, searchText.length) else option.label
$(option.dom_id).update(text)
results += 1 if option.search_match
else if not (@is_multiple and option.selected)
found = this.winnow_search_match(regex, option.html)
results += 1 if found

result_id = option.dom_id

if found or (option.group_array_index? && @results_data[option.group_array_index].search_match)
if found or (@search_optgroup && option.group_array_index? && @results_data[option.group_array_index].search_match)
if searchText.length and found
text = this.winnow_search_highlight_match(zregex, option.html, searchText.length)
else
Expand Down
1 change: 1 addition & 0 deletions coffee/lib/abstract-chosen.coffee
Expand Up @@ -31,6 +31,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
@search_contains = @options.search_contains || false
@search_optgroup = if @options.search_optgroup? then @options.search_optgroup else true
@choices = 0
@single_backstroke_delete = @options.single_backstroke_delete || false
@max_selected_options = @options.max_selected_options || Infinity
Expand Down

0 comments on commit 8273084

Please sign in to comment.