devbridge / jQuery-Autocomplete

Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields
https://www.devbridge.com/sourcery/components/jquery-autocomplete/
Other
3.56k stars 1.66k forks source link

Accent insensitive #355

Open Marsupio opened 9 years ago

Marsupio commented 9 years ago

For many languages, it is important that queries are accent insensitive, because people tend to write words without the corresponding accents, so it often happens that the expected suggestions do not show. Therefore, lookupFilter should include accent sensitiveness option. There is already some code on this, so implementation should be easy: http://scripterlative.com/files/noaccent.htm

elMatadito commented 8 years ago

I have written a function for this problem, and I implemented in lookupFilter:

$('#country_value').autocomplete({ lookup: countries, lookupFilter: function (suggestion, originalQuery, queryLowerCase) { return suggestion.value.toLowerCase().indexOf(normalize(queryLowerCase)) !== -1; } });

Here the code for normalize():

var accentMap = { "á": "a", "é": "e", "í": "i", "ó": "o", "ú": "u" }; var normalize = function (term) { var returnNormalize = ""; for (var i = 0; i < term.length; i++) { returnNormalize += accentMap[term.charAt(i)] || term.charAt(i); } return returnNormalize; };