2
0
mirror of https://github.com/devbridge/jQuery-Autocomplete.git synced 2024-11-08 14:20:59 +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 = {
"AD": "Andorra",
"A2": "Andorra Test",
"AE": "United Arab Emirates",
"AF": "Afghanistan",
"AG": "Antigua and Barbuda",

View File

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