Skip to content

Instantly share code, notes, and snippets.

@atatos
Created July 27, 2013 17:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atatos/6095595 to your computer and use it in GitHub Desktop.
Save atatos/6095595 to your computer and use it in GitHub Desktop.
this is an example of the autocomplete jQuery ui ( JSON & Bold hightlighted)
$("#search-txt").autocomplete({
source: function (req, responseFn) {
$.ajax({
url: "/search.json",
dataType: "json",
success: function(data) {
var re = $.ui.autocomplete.escapeRegex(req.term);
var matcher = new RegExp( "^" + re, "i" );
var a = $.grep( data, function(item,index){
return matcher.test(item.value);
});
responseFn( a );
},
error: function (error) {
}
});
}
}).data('ui-autocomplete')._renderItem = function( ul, item) {
var re = new RegExp("^" + this.term, "i") ;
var t = item.value.replace(re,"<span style='font-weight:600;'>" + this.term + "</span>");
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + t + "</a>" )
.appendTo( ul );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment