I am overriding jQuery Autocomplete to display simple links (<a href=...>
") and some extra formatting that will need to become more complex later.
Nothing happens when the links are clicked. Is there a way to remove whatever event handler or other code is intercepting clicks so that they behave as expected?
There are several related questions (eg #4536055) with good answers, but they deal with the default Autocomplete behavior. The source
answer seems like a hack -- links should function like links.
My code:
$.widget( "custom.complete_custom", $.ui.autocomplete, {
_renderMenu: function( ul, items ) {
// Trigger a "See all" link if there are two many results
var self = this;
var too_long = false;
if (items.length > 10){
original_length = items.length;
too_long = true;
items = items.slice(0,10);
}
// Display each result as a link
$.each( items, function( index, item ) {
ul.append( "<li class='ui-autocomplete-category'><a href='/building/" + item.buildingcode + "'>" + item.buildingname + "</a></li>" );
});
// Add the "See all" link if necessary
if(too_long) {
ul.append( "<li class='ui-autocomplete-category see-all'><a href='/search/" + 'term' + "'><strong>See all " + original_length + " results</strong></a></li>" )
}
}
});
// The autocomplete activator
$( "#search" ).complete_custom({
source: "/search/json",
minLength: 2
});