David Canós
David Canós

Reputation: 1994

Cant override jQuery UI autocomplete renderItem method multiple times

It overrides properly in the first autocomplete found, but do nothing with the rest. Instead it loads the original _renderitem method that you can see at https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.autocomplete.js#L449.

$(".someClassWithMultipleItemsOnDOM").autocomplete({
        delay:500,
        minLength:2,
        source:path"
        .....   
}).data( "autocomplete" )._renderItem = function( ul, item ) {

thanks in advance

Upvotes: 8

Views: 9146

Answers (2)

Damax
Damax

Reputation: 1487

You can override _renderItem

$.ui.autocomplete.prototype._renderItem = function (ul, item) { ... };

Upvotes: 10

tomc
tomc

Reputation: 1458

There's a workaround for this problem:

var autoc = {
    delay: 500,
    minLength: 2,
    source: path,
    .....   
};

var renderItem = function (ul, item) {
    return $("<li></li>")
        .data("item.autocomplete", item)
        .append("<a>" + item.label + "<br/>" + item.desc + "</a>")
        .appendTo(ul);
};

$(".someClassWithMultipleItemsOnDOM").each(function (i) {
     $(this).autocomplete(autoc).data("autocomplete")._renderItem = renderItem;
}

Upvotes: 19

Related Questions