jQuery-Autocomplete icon indicating copy to clipboard operation
jQuery-Autocomplete copied to clipboard

Accent insensitive

Open Marsupio opened this issue 10 years ago • 1 comments

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

Marsupio avatar Apr 19 '15 14:04 Marsupio

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; };

elMatadito avatar Oct 12 '16 14:10 elMatadito