jQuery-Autocomplete
jQuery-Autocomplete copied to clipboard
Accent insensitive
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
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; };