Skip to content

Commit

Permalink
Show add item link even for prefix matches
Browse files Browse the repository at this point in the history
  • Loading branch information
kamal authored and koenpunt committed May 10, 2013
1 parent a27beca commit 28df6d5
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions chosen/chosen.jquery.js
Expand Up @@ -863,14 +863,15 @@ Copyright (c) 2011 by Harvest
};

Chosen.prototype.winnow_results = function() {
var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, selected, startpos, text, zregex, _i, _j, _len, _len1, _ref;
var exactRegex, found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, selected, startpos, text, zregex, _i, _j, _len, _len1, _ref;
this.no_results_clear();
results = 0;
selected = false;
searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
regexAnchor = this.search_contains ? "" : "^";
regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
exactRegex = new RegExp('^' + searchText + '$', 'i');
_ref = this.results_data;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
option = _ref[_i];
Expand Down Expand Up @@ -916,7 +917,7 @@ Copyright (c) 2011 by Harvest
this.result_deactivate(result);
}
} else if (this.is_multiple && option.selected) {
if (regex.test(option.html)) {
if (exactRegex.test(option.html)) {
selected = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion chosen/chosen.jquery.min.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions chosen/chosen.proto.js
Expand Up @@ -865,14 +865,15 @@ Copyright (c) 2011 by Harvest
};

Chosen.prototype.winnow_results = function() {
var found, option, part, parts, regex, regexAnchor, result_id, results, searchText, selected, startpos, text, zregex, _i, _j, _len, _len1, _ref;
var exactRegex, found, option, part, parts, regex, regexAnchor, result_id, results, searchText, selected, startpos, text, zregex, _i, _j, _len, _len1, _ref;
this.no_results_clear();
results = 0;
selected = false;
searchText = this.search_field.value === this.default_text ? "" : this.search_field.value.strip().escapeHTML();
regexAnchor = this.search_contains ? "" : "^";
regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
exactRegex = new RegExp('^' + searchText + '$', 'i');
_ref = this.results_data;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
option = _ref[_i];
Expand Down Expand Up @@ -921,7 +922,7 @@ Copyright (c) 2011 by Harvest
this.result_deactivate($(result_id));
}
} else if (this.is_multiple && option.selected) {
if (regex.test(option.html)) {
if (exactRegex.test(option.html)) {
selected = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion chosen/chosen.proto.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion coffee/chosen.jquery.coffee
Expand Up @@ -406,6 +406,7 @@ class Chosen extends AbstractChosen
regexAnchor = if @search_contains then "" else "^"
regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
exactRegex = new RegExp('^' + searchText + '$', 'i')

for option in @results_data
if not option.disabled and not option.empty
Expand Down Expand Up @@ -444,7 +445,7 @@ class Chosen extends AbstractChosen
this.result_clear_highlight() if @result_highlight and result_id is @result_highlight.attr 'id'
this.result_deactivate result
else if (@is_multiple and option.selected)
selected = true if regex.test option.html
selected = true if exactRegex.test option.html

if results < 1 and searchText.length
this.no_results searchText, selected
Expand Down
3 changes: 2 additions & 1 deletion coffee/chosen.proto.coffee
Expand Up @@ -398,6 +398,7 @@ class Chosen extends AbstractChosen
regexAnchor = if @search_contains then "" else "^"
regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
exactRegex = new RegExp('^' + searchText + '$', 'i')

for option in @results_data
if not option.disabled and not option.empty
Expand Down Expand Up @@ -436,7 +437,7 @@ class Chosen extends AbstractChosen
this.result_clear_highlight() if $(result_id) is @result_highlight
this.result_deactivate $(result_id)
else if (@is_multiple and option.selected)
selected = true if regex.test option.html
selected = true if exactRegex.test option.html

if results < 1 and searchText.length
this.no_results(searchText, selected)
Expand Down

0 comments on commit 28df6d5

Please sign in to comment.