diff --git a/scripts/countries.js b/scripts/countries.js index 1e5bee6..7d41ee4 100644 --- a/scripts/countries.js +++ b/scripts/countries.js @@ -1,5 +1,6 @@ var countries = { "AD": "Andorra", + "A2": "Andorra Test", "AE": "United Arab Emirates", "AF": "Afghanistan", "AG": "Antigua and Barbuda", diff --git a/src/jquery.autocomplete.js b/src/jquery.autocomplete.js index 983fe45..353f186 100644 --- a/src/jquery.autocomplete.js +++ b/src/jquery.autocomplete.js @@ -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 '