mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2024-11-22 04:45:12 +00:00
Do not trigger select on valid input when multiple suggestions are available, fixes #361
This commit is contained in:
parent
afdece2298
commit
ab1c27b673
@ -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",
|
||||||
|
@ -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,12 +476,9 @@
|
|||||||
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) {
|
return;
|
||||||
that.select(index);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.length < options.minChars) {
|
if (query.length < options.minChars) {
|
||||||
@ -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,15 +655,11 @@
|
|||||||
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) {
|
return;
|
||||||
that.select(index);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build suggestions inner HTML:
|
// Build suggestions inner HTML:
|
||||||
|
Loading…
Reference in New Issue
Block a user