JQuery autocomplete with special characters (i.e. ö, Ä, é or ß)

How can I autocomplete the coincidence of words with special characters, for example, in German: ö, Ä, é or ß. For example, I would like mun to match München and Munchen.

+4
source share
3 answers

There's a great article about it on A List Apart , which includes Javascript code

var accentMap = { 'á': 'a', 'é': 'e', 'í': 'i', 'ó': 'o', 'ú': 'u' }; function accent_fold(s) { if (!s) { return ''; } var ret = ''; for (var i = 0; i < s.length; i++) { ret += accent_map[s.charAt(i)] || s.charAt(i); } return ret; }; 
+3
source

I use typeahead, and after hours of banging my head against the wall, it was as easy as using utf8_encode in a script that returns JSON:

utf8_encode (stripslashes (variable $));

+2
source

jQuery UI has a demo for this problem (emphasis addition) on its website: https://jqueryui.com/autocomplete/#folding

 $(function() { var names = ["Jörn Zaefferer", "Scott González", "John Resig"]; var accentMap = { "á": "a", "ö": "o" }; var normalize = function(term) { var ret = ""; for (var i = 0; i < term.length; i++) { ret += accentMap[term.charAt(i)] || term.charAt(i); } return ret; }; $("#developer").autocomplete({ source: function(request, response) { var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i"); response($.grep(names, function(value) { value = value.label || value.value || value; return matcher.test(value) || matcher.test(normalize(value)); })); } }); }); 
0
source

All Articles