Skip to content

Instantly share code, notes, and snippets.

@krosti
Created March 14, 2013 17:45
Show Gist options
  • Save krosti/5163477 to your computer and use it in GitHub Desktop.
Save krosti/5163477 to your computer and use it in GitHub Desktop.
jquery UI - autocomplete - accent folding example
$(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 ) );
}) );
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment