Created
March 14, 2013 17:45
-
-
Save krosti/5163477 to your computer and use it in GitHub Desktop.
jquery UI - autocomplete - accent folding example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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