Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add an option to disable search in each word. #824

Merged
merged 3 commits into from

3 participants

@Goutet

Allow to disable the search on each separate word in an option text.
All js files generated using cake and uglify.

coffee/chosen.jquery.coffee
@@ -410,6 +410,7 @@ class Chosen extends AbstractChosen
results = 0
+ split_words = !this.options.do_not_split
@stof Collaborator
stof added a note

You should handle the option in AbstractChosen like others, to allow handling the default value.

And do_not_split does not seem a good name to me. What it is about ? Existing options related to configuring the search are all using search in their name (disable_search, search_contains, disable_search_threshold)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Goutet

When searching search text in each option html, chosen first runs a regex on the whole option html, then , if not found on each separate word. The aim of the option is to disable this second search pass when not necessary or even unwanted.
So I suggest to use "@options.disable_search_split_words" as option name with default value false (usual behaviour).
If you agree with the name, I will push the changes.
Thanks

@pfiller pfiller commented on the diff
coffee/lib/abstract-chosen.coffee
@@ -30,6 +30,7 @@ class AbstractChosen
@allow_single_deselect = if @options.allow_single_deselect? and @form_field.options[0]? and @form_field.options[0].text is "" then @options.allow_single_deselect else false
@disable_search_threshold = @options.disable_search_threshold || 0
@disable_search = @options.disable_search || false
+ @search_split_words = not (@options.disable_search_split_words || false)
@pfiller Owner
pfiller added a note

This is a little awkward, but I think that's my fault. Given how other options work, I think this is a pretty fair compromise.

@stof Collaborator
stof added a note

why not calling the option enable_search_split_words or something like that ? we already have afffirmative names, for instance allow_single_deselect

@Goutet
Goutet added a note

I chose "disable" in order to keep current behaviour on default false value. But as noted, it can be changed, considering also other search options like @search_contains.

@pfiller Owner
pfiller added a note

I agree - we could have done this a little simpler. Opened a PR #940

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@pfiller pfiller merged commit da35384 into harvesthq:master
@pfiller
Owner

Thanks @Goutet. This is an interesting option that might help improve performance for some users. I wonder if it should always be true if @search_contains is on. Something to play with...

@pfiller pfiller referenced this pull request from a commit
@pfiller pfiller Uprade to version 0.9.11
- #824, #940 Add an option to disable searching split words
- #917 Add an option to inherit initial select classes
4371e8f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 19, 2012
  1. @Goutet
Commits on Oct 5, 2012
  1. @Goutet
Commits on Nov 7, 2012
  1. @Goutet

    Merge with harvestq master

    Goutet authored
This page is out of date. Refresh to see the latest.
View
107 chosen/chosen.jquery.js
@@ -47,7 +47,9 @@
SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
if (option.nodeName.toUpperCase() === "OPTION") {
if (option.text !== "") {
- if (group_position != null) this.parsed[group_position].children += 1;
+ if (group_position != null) {
+ this.parsed[group_position].children += 1;
+ }
this.parsed.push({
array_index: this.parsed.length,
options_index: this.options_index,
@@ -95,6 +97,7 @@ Chosen source: generate output using 'cake build'
Copyright (c) 2011 by Harvest
*/
+
(function() {
var AbstractChosen, root;
@@ -130,6 +133,7 @@ Copyright (c) 2011 by Harvest
this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
this.disable_search_threshold = this.options.disable_search_threshold || 0;
this.disable_search = this.options.disable_search || false;
+ this.search_split_words = !(this.options.disable_search_split_words || false);
this.search_contains = this.options.search_contains || false;
this.choices = 0;
this.single_backstroke_delete = this.options.single_backstroke_delete || false;
@@ -183,9 +187,15 @@ Copyright (c) 2011 by Harvest
if (!option.disabled) {
option.dom_id = this.container_id + "_o_" + option.array_index;
classes = option.selected && this.is_multiple ? [] : ["active-result"];
- if (option.selected) classes.push("result-selected");
- if (option.group_array_index != null) classes.push("group-option");
- if (option.classes !== "") classes.push(option.classes);
+ if (option.selected) {
+ classes.push("result-selected");
+ }
+ if (option.group_array_index != null) {
+ classes.push("group-option");
+ }
+ if (option.classes !== "") {
+ classes.push(option.classes);
+ }
style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : "";
return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '"' + style + '>' + option.html + '</li>';
} else {
@@ -194,7 +204,9 @@ Copyright (c) 2011 by Harvest
};
AbstractChosen.prototype.results_update_field = function() {
- if (!this.is_multiple) this.results_reset_cleanup();
+ if (!this.is_multiple) {
+ this.results_reset_cleanup();
+ }
this.result_clear_highlight();
this.result_single_selected = null;
return this.results_build();
@@ -231,10 +243,14 @@ Copyright (c) 2011 by Harvest
break;
case 13:
evt.preventDefault();
- if (this.results_showing) return this.result_select(evt);
+ if (this.results_showing) {
+ return this.result_select(evt);
+ }
break;
case 27:
- if (this.results_showing) this.results_hide();
+ if (this.results_showing) {
+ this.results_hide();
+ }
return true;
case 9:
case 38:
@@ -275,10 +291,11 @@ Chosen source: generate output using 'cake build'
Copyright (c) 2011 by Harvest
*/
+
(function() {
var $, Chosen, get_side_border_padding, root,
- __hasProp = Object.prototype.hasOwnProperty,
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
+ __hasProp = {}.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
root = this;
@@ -304,7 +321,7 @@ Copyright (c) 2011 by Harvest
__extends(Chosen, _super);
function Chosen() {
- Chosen.__super__.constructor.apply(this, arguments);
+ return Chosen.__super__.constructor.apply(this, arguments);
}
Chosen.prototype.setup = function() {
@@ -446,7 +463,9 @@ Copyright (c) 2011 by Harvest
}
if (!this.pending_destroy_click && !target_closelink) {
if (!this.active_field) {
- if (this.is_multiple) this.search_field.val("");
+ if (this.is_multiple) {
+ this.search_field.val("");
+ }
$(document).click(this.click_test_action);
this.results_show();
} else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chzn-single").length)) {
@@ -525,7 +544,9 @@ Copyright (c) 2011 by Harvest
this.choice_build(data);
} else if (data.selected && !this.is_multiple) {
this.selected_item.removeClass("chzn-default").find("span").text(data.text);
- if (this.allow_single_deselect) this.single_deselect_control_build();
+ if (this.allow_single_deselect) {
+ this.single_deselect_control_build();
+ }
}
}
}
@@ -565,7 +586,9 @@ Copyright (c) 2011 by Harvest
};
Chosen.prototype.result_clear_highlight = function() {
- if (this.result_highlight) this.result_highlight.removeClass("highlighted");
+ if (this.result_highlight) {
+ this.result_highlight.removeClass("highlighted");
+ }
return this.result_highlight = null;
};
@@ -642,7 +665,9 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.search_results_mouseover = function(evt) {
var target;
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
- if (target) return this.result_do_highlight(target);
+ if (target) {
+ return this.result_do_highlight(target);
+ }
};
Chosen.prototype.search_results_mouseout = function(evt) {
@@ -705,11 +730,15 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.results_reset = function() {
this.form_field.options[0].selected = true;
this.selected_item.find("span").text(this.default_text);
- if (!this.is_multiple) this.selected_item.addClass("chzn-default");
+ if (!this.is_multiple) {
+ this.selected_item.addClass("chzn-default");
+ }
this.show_search_field_default();
this.results_reset_cleanup();
this.form_field_jq.trigger("change");
- if (this.active_field) return this.results_hide();
+ if (this.active_field) {
+ return this.results_hide();
+ }
};
Chosen.prototype.results_reset_cleanup = function() {
@@ -739,9 +768,13 @@ Copyright (c) 2011 by Harvest
this.choice_build(item);
} else {
this.selected_item.find("span").first().text(item.text);
- if (this.allow_single_deselect) this.single_deselect_control_build();
+ if (this.allow_single_deselect) {
+ this.single_deselect_control_build();
+ }
+ }
+ if (!(evt.metaKey && this.is_multiple)) {
+ this.results_hide();
}
- if (!(evt.metaKey && this.is_multiple)) this.results_hide();
this.search_field.val("");
if (this.is_multiple || this.form_field_jq.val() !== this.current_value) {
this.form_field_jq.trigger("change", {
@@ -788,7 +821,7 @@ Copyright (c) 2011 by Harvest
};
Chosen.prototype.winnow_results = function() {
- var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref;
+ var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref;
this.no_results_clear();
results = 0;
searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
@@ -808,10 +841,10 @@ Copyright (c) 2011 by Harvest
if (regex.test(option.html)) {
found = true;
results += 1;
- } else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) {
+ } else if (this.search_split_words && (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0)) {
parts = option.html.replace(/\[|\]/g, "").split(" ");
if (parts.length) {
- for (_j = 0, _len2 = parts.length; _j < _len2; _j++) {
+ for (_j = 0, _len1 = parts.length; _j < _len1; _j++) {
part = parts[_j];
if (regex.test(part)) {
found = true;
@@ -873,7 +906,9 @@ Copyright (c) 2011 by Harvest
if (!this.result_highlight) {
selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
- if (do_high != null) return this.result_do_highlight(do_high);
+ if (do_high != null) {
+ return this.result_do_highlight(do_high);
+ }
}
};
@@ -892,12 +927,18 @@ Copyright (c) 2011 by Harvest
var first_active, next_sib;
if (!this.result_highlight) {
first_active = this.search_results.find("li.active-result").first();
- if (first_active) this.result_do_highlight($(first_active));
+ if (first_active) {
+ this.result_do_highlight($(first_active));
+ }
} else if (this.results_showing) {
next_sib = this.result_highlight.nextAll("li.active-result").first();
- if (next_sib) this.result_do_highlight(next_sib);
+ if (next_sib) {
+ this.result_do_highlight(next_sib);
+ }
+ }
+ if (!this.results_showing) {
+ return this.results_show();
}
- if (!this.results_showing) return this.results_show();
};
Chosen.prototype.keyup_arrow = function() {
@@ -909,7 +950,9 @@ Copyright (c) 2011 by Harvest
if (prev_sibs.length) {
return this.result_do_highlight(prev_sibs.first());
} else {
- if (this.choices > 0) this.results_hide();
+ if (this.choices > 0) {
+ this.results_hide();
+ }
return this.result_clear_highlight();
}
}
@@ -944,13 +987,17 @@ Copyright (c) 2011 by Harvest
var stroke, _ref;
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
this.search_field_scale();
- if (stroke !== 8 && this.pending_backstroke) this.clear_backstroke();
+ if (stroke !== 8 && this.pending_backstroke) {
+ this.clear_backstroke();
+ }
switch (stroke) {
case 8:
this.backstroke_length = this.search_field.val().length;
break;
case 9:
- if (this.results_showing && !this.is_multiple) this.result_select(evt);
+ if (this.results_showing && !this.is_multiple) {
+ this.result_select(evt);
+ }
this.mouse_on_container = false;
break;
case 13:
@@ -984,7 +1031,9 @@ Copyright (c) 2011 by Harvest
$('body').append(div);
w = div.width() + 25;
div.remove();
- if (w > this.f_width - 10) w = this.f_width - 10;
+ if (w > this.f_width - 10) {
+ w = this.f_width - 10;
+ }
this.search_field.css({
'width': w + 'px'
});
View
115 chosen/chosen.proto.js
@@ -47,7 +47,9 @@
SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
if (option.nodeName.toUpperCase() === "OPTION") {
if (option.text !== "") {
- if (group_position != null) this.parsed[group_position].children += 1;
+ if (group_position != null) {
+ this.parsed[group_position].children += 1;
+ }
this.parsed.push({
array_index: this.parsed.length,
options_index: this.options_index,
@@ -95,6 +97,7 @@ Chosen source: generate output using 'cake build'
Copyright (c) 2011 by Harvest
*/
+
(function() {
var AbstractChosen, root;
@@ -130,6 +133,7 @@ Copyright (c) 2011 by Harvest
this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
this.disable_search_threshold = this.options.disable_search_threshold || 0;
this.disable_search = this.options.disable_search || false;
+ this.search_split_words = !(this.options.disable_search_split_words || false);
this.search_contains = this.options.search_contains || false;
this.choices = 0;
this.single_backstroke_delete = this.options.single_backstroke_delete || false;
@@ -183,9 +187,15 @@ Copyright (c) 2011 by Harvest
if (!option.disabled) {
option.dom_id = this.container_id + "_o_" + option.array_index;
classes = option.selected && this.is_multiple ? [] : ["active-result"];
- if (option.selected) classes.push("result-selected");
- if (option.group_array_index != null) classes.push("group-option");
- if (option.classes !== "") classes.push(option.classes);
+ if (option.selected) {
+ classes.push("result-selected");
+ }
+ if (option.group_array_index != null) {
+ classes.push("group-option");
+ }
+ if (option.classes !== "") {
+ classes.push(option.classes);
+ }
style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : "";
return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '"' + style + '>' + option.html + '</li>';
} else {
@@ -194,7 +204,9 @@ Copyright (c) 2011 by Harvest
};
AbstractChosen.prototype.results_update_field = function() {
- if (!this.is_multiple) this.results_reset_cleanup();
+ if (!this.is_multiple) {
+ this.results_reset_cleanup();
+ }
this.result_clear_highlight();
this.result_single_selected = null;
return this.results_build();
@@ -231,10 +243,14 @@ Copyright (c) 2011 by Harvest
break;
case 13:
evt.preventDefault();
- if (this.results_showing) return this.result_select(evt);
+ if (this.results_showing) {
+ return this.result_select(evt);
+ }
break;
case 27:
- if (this.results_showing) this.results_hide();
+ if (this.results_showing) {
+ this.results_hide();
+ }
return true;
case 9:
case 38:
@@ -275,10 +291,11 @@ Chosen source: generate output using 'cake build'
Copyright (c) 2011 by Harvest
*/
+
(function() {
var Chosen, get_side_border_padding, root,
- __hasProp = Object.prototype.hasOwnProperty,
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
+ __hasProp = {}.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
root = this;
@@ -287,7 +304,7 @@ Copyright (c) 2011 by Harvest
__extends(Chosen, _super);
function Chosen() {
- Chosen.__super__.constructor.apply(this, arguments);
+ return Chosen.__super__.constructor.apply(this, arguments);
}
Chosen.prototype.setup = function() {
@@ -433,10 +450,14 @@ Copyright (c) 2011 by Harvest
var target_closelink;
if (!this.is_disabled) {
target_closelink = evt != null ? evt.target.hasClassName("search-choice-close") : false;
- if (evt && evt.type === "mousedown" && !this.results_showing) evt.stop();
+ if (evt && evt.type === "mousedown" && !this.results_showing) {
+ evt.stop();
+ }
if (!this.pending_destroy_click && !target_closelink) {
if (!this.active_field) {
- if (this.is_multiple) this.search_field.clear();
+ if (this.is_multiple) {
+ this.search_field.clear();
+ }
document.observe("click", this.click_test_action);
this.results_show();
} else if (!this.is_multiple && evt && (evt.target === this.selected_item || evt.target.up("a.chzn-single"))) {
@@ -514,7 +535,9 @@ Copyright (c) 2011 by Harvest
this.choice_build(data);
} else if (data.selected && !this.is_multiple) {
this.selected_item.removeClassName("chzn-default").down("span").update(data.html);
- if (this.allow_single_deselect) this.single_deselect_control_build();
+ if (this.allow_single_deselect) {
+ this.single_deselect_control_build();
+ }
}
}
}
@@ -631,7 +654,9 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.search_results_mouseover = function(evt) {
var target;
target = evt.target.hasClassName("active-result") ? evt.target : evt.target.up(".active-result");
- if (target) return this.result_do_highlight(target);
+ if (target) {
+ return this.result_do_highlight(target);
+ }
};
Chosen.prototype.search_results_mouseout = function(evt) {
@@ -695,18 +720,26 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.results_reset = function() {
this.form_field.options[0].selected = true;
this.selected_item.down("span").update(this.default_text);
- if (!this.is_multiple) this.selected_item.addClassName("chzn-default");
+ if (!this.is_multiple) {
+ this.selected_item.addClassName("chzn-default");
+ }
this.show_search_field_default();
this.results_reset_cleanup();
- if (typeof Event.simulate === 'function') this.form_field.simulate("change");
- if (this.active_field) return this.results_hide();
+ if (typeof Event.simulate === 'function') {
+ this.form_field.simulate("change");
+ }
+ if (this.active_field) {
+ return this.results_hide();
+ }
};
Chosen.prototype.results_reset_cleanup = function() {
var deselect_trigger;
this.current_value = this.form_field.value;
deselect_trigger = this.selected_item.down("abbr");
- if (deselect_trigger) return deselect_trigger.remove();
+ if (deselect_trigger) {
+ return deselect_trigger.remove();
+ }
};
Chosen.prototype.result_select = function(evt) {
@@ -730,9 +763,13 @@ Copyright (c) 2011 by Harvest
this.choice_build(item);
} else {
this.selected_item.down("span").update(item.html);
- if (this.allow_single_deselect) this.single_deselect_control_build();
+ if (this.allow_single_deselect) {
+ this.single_deselect_control_build();
+ }
+ }
+ if (!(evt.metaKey && this.is_multiple)) {
+ this.results_hide();
}
- if (!(evt.metaKey && this.is_multiple)) this.results_hide();
this.search_field.value = "";
if (typeof Event.simulate === 'function' && (this.is_multiple || this.form_field.value !== this.current_value)) {
this.form_field.simulate("change");
@@ -779,7 +816,7 @@ Copyright (c) 2011 by Harvest
};
Chosen.prototype.winnow_results = function() {
- var found, option, part, parts, regex, regexAnchor, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref;
+ var found, option, part, parts, regex, regexAnchor, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref;
this.no_results_clear();
results = 0;
searchText = this.search_field.value === this.default_text ? "" : this.search_field.value.strip().escapeHTML();
@@ -798,10 +835,10 @@ Copyright (c) 2011 by Harvest
if (regex.test(option.html)) {
found = true;
results += 1;
- } else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) {
+ } else if (this.search_split_words && (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0)) {
parts = option.html.replace(/\[|\]/g, "").split(" ");
if (parts.length) {
- for (_j = 0, _len2 = parts.length; _j < _len2; _j++) {
+ for (_j = 0, _len1 = parts.length; _j < _len1; _j++) {
part = parts[_j];
if (regex.test(part)) {
found = true;
@@ -818,7 +855,9 @@ Copyright (c) 2011 by Harvest
} else {
text = option.html;
}
- if ($(result_id).innerHTML !== text) $(result_id).update(text);
+ if ($(result_id).innerHTML !== text) {
+ $(result_id).update(text);
+ }
this.result_activate($(result_id));
if (option.group_array_index != null) {
$(this.results_data[option.group_array_index].dom_id).setStyle({
@@ -868,7 +907,9 @@ Copyright (c) 2011 by Harvest
if (!(do_high != null)) {
do_high = this.search_results.down(".active-result");
}
- if (do_high != null) return this.result_do_highlight(do_high);
+ if (do_high != null) {
+ return this.result_do_highlight(do_high);
+ }
}
};
@@ -897,9 +938,13 @@ Copyright (c) 2011 by Harvest
} else if (this.results_showing) {
sibs = this.result_highlight.nextSiblings();
nexts = sibs.intersect(actives);
- if (nexts.length) this.result_do_highlight(nexts.first());
+ if (nexts.length) {
+ this.result_do_highlight(nexts.first());
+ }
+ }
+ if (!this.results_showing) {
+ return this.results_show();
}
- if (!this.results_showing) return this.results_show();
}
};
@@ -914,7 +959,9 @@ Copyright (c) 2011 by Harvest
if (prevs.length) {
return this.result_do_highlight(prevs.first());
} else {
- if (this.choices > 0) this.results_hide();
+ if (this.choices > 0) {
+ this.results_hide();
+ }
return this.result_clear_highlight();
}
}
@@ -952,13 +999,17 @@ Copyright (c) 2011 by Harvest
var stroke, _ref;
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
this.search_field_scale();
- if (stroke !== 8 && this.pending_backstroke) this.clear_backstroke();
+ if (stroke !== 8 && this.pending_backstroke) {
+ this.clear_backstroke();
+ }
switch (stroke) {
case 8:
this.backstroke_length = this.search_field.value.length;
break;
case 9:
- if (this.results_showing && !this.is_multiple) this.result_select(evt);
+ if (this.results_showing && !this.is_multiple) {
+ this.result_select(evt);
+ }
this.mouse_on_container = false;
break;
case 13:
@@ -991,7 +1042,9 @@ Copyright (c) 2011 by Harvest
document.body.appendChild(div);
w = Element.measure(div, 'width') + 25;
div.remove();
- if (w > this.f_width - 10) w = this.f_width - 10;
+ if (w > this.f_width - 10) {
+ w = this.f_width - 10;
+ }
this.search_field.setStyle({
'width': w + 'px'
});
View
2  coffee/chosen.jquery.coffee
@@ -416,7 +416,7 @@ class Chosen extends AbstractChosen
if regex.test option.html
found = true
results += 1
- else if option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0
+ else if @search_split_words and (option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0)
#TODO: replace this substitution of /\[\]/ with a list of characters to skip.
parts = option.html.replace(/\[|\]/g, "").split(" ")
if parts.length
View
2  coffee/chosen.proto.coffee
@@ -401,7 +401,7 @@ class Chosen extends AbstractChosen
if regex.test option.html
found = true
results += 1
- else if option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0
+ else if @search_split_words and (option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0)
#TODO: replace this substitution of /\[\]/ with a list of characters to skip.
parts = option.html.replace(/\[|\]/g, "").split(" ")
if parts.length
View
1  coffee/lib/abstract-chosen.coffee
@@ -30,6 +30,7 @@ class AbstractChosen
@allow_single_deselect = if @options.allow_single_deselect? and @form_field.options[0]? and @form_field.options[0].text is "" then @options.allow_single_deselect else false
@disable_search_threshold = @options.disable_search_threshold || 0
@disable_search = @options.disable_search || false
+ @search_split_words = not (@options.disable_search_split_words || false)
@pfiller Owner
pfiller added a note

This is a little awkward, but I think that's my fault. Given how other options work, I think this is a pretty fair compromise.

@stof Collaborator
stof added a note

why not calling the option enable_search_split_words or something like that ? we already have afffirmative names, for instance allow_single_deselect

@Goutet
Goutet added a note

I chose "disable" in order to keep current behaviour on default false value. But as noted, it can be changed, considering also other search options like @search_contains.

@pfiller Owner
pfiller added a note

I agree - we could have done this a little simpler. Opened a PR #940

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@search_contains = @options.search_contains || false
@choices = 0
@single_backstroke_delete = @options.single_backstroke_delete || false
Something went wrong with that request. Please try again.