2
0
mirror of https://github.com/devbridge/jQuery-Autocomplete.git synced 2024-11-09 23:01:00 +00:00

Do not trigger select on valid input when multiple suggestions are available, fixes #361

This commit is contained in:
Tomas Kirda 2015-05-16 12:03:08 -05:00
parent afdece2298
commit ab1c27b673
2 changed files with 12 additions and 28 deletions

View File

@ -1,5 +1,6 @@
var countries = { var countries = {
"AD": "Andorra", "AD": "Andorra",
"A2": "Andorra Test",
"AE": "United Arab Emirates", "AE": "United Arab Emirates",
"AF": "Afghanistan", "AF": "Afghanistan",
"AG": "Antigua and Barbuda", "AG": "Antigua and Barbuda",

View File

@ -464,8 +464,7 @@
var that = this, var that = this,
options = that.options, options = that.options,
value = that.el.val(), value = that.el.val(),
query = that.getQuery(value), query = that.getQuery(value);
index;
if (that.selection && that.currentValue !== query) { if (that.selection && that.currentValue !== query) {
that.selection = null; that.selection = null;
@ -477,13 +476,10 @@
that.selectedIndex = -1; that.selectedIndex = -1;
// Check existing suggestion for the match before proceeding: // Check existing suggestion for the match before proceeding:
if (options.triggerSelectOnValidInput) { if (options.triggerSelectOnValidInput && that.isExactMatch(query)) {
index = that.findSuggestionIndex(query); that.select(0);
if (index !== -1) {
that.select(index);
return; return;
} }
}
if (query.length < options.minChars) { if (query.length < options.minChars) {
that.hide(); that.hide();
@ -492,19 +488,10 @@
} }
}, },
findSuggestionIndex: function (query) { isExactMatch: function (query) {
var that = this, var suggestions = this.suggestions;
index = -1,
queryLowerCase = query.toLowerCase();
$.each(that.suggestions, function (i, suggestion) { return (suggestions.length === 1 && suggestions[0].value.toLowerCase() === query.toLowerCase());
if (suggestion.value.toLowerCase() === queryLowerCase) {
index = i;
return false;
}
});
return index;
}, },
getQuery: function (value) { getQuery: function (value) {
@ -668,16 +655,12 @@
category = currentCategory; category = currentCategory;
return '<div class="autocomplete-group"><strong>' + category + '</strong></div>'; return '<div class="autocomplete-group"><strong>' + category + '</strong></div>';
}, };
index;
if (options.triggerSelectOnValidInput) { if (options.triggerSelectOnValidInput && that.isExactMatch(value)) {
index = that.findSuggestionIndex(value); that.select(0);
if (index !== -1) {
that.select(index);
return; return;
} }
}
// Build suggestions inner HTML: // Build suggestions inner HTML:
$.each(that.suggestions, function (i, suggestion) { $.each(that.suggestions, function (i, suggestion) {