Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI custom AutoComplete - `_renderItem` and `_renderMenu` not working

I've used some code from a combobox demo, and now that i am trying to add some classes to the list-items, the _renderItem and _renderMenu, has no effect.

the code (with some irrelevant lines, to make sure that i miss nothing)

this.input = $("<input>")
    .appendTo(this.wrapper)
    .val(value)
    .attr("title", "")
    .addClass("custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left")
    .autocomplete({
        autoFocus: true,
        response: function (event, ui) {
            if (ui.content.length == 0) {
                    ui.content.push({
                        label: "new value: " + $(this).val(),
                        value: $(this).val(),
                        id: 0
                    });
            }
        },
        _renderItem: function (ul, item) {
            return $("<li>")
                .addClass("Please work")
                .attr("data-value", item.value)
                .append(item.label)
                .appendTo(ul);
        },
        _renderMenu: function (ul, items) {
            var that = this;
            $.each(items, function (index, item) {
                that._renderItemData(ul, item);
            });
            $(ul).find("li:odd").addClass("odd");
        },
        delay: 0,
        minLength: 0,
        source: $.proxy(this, "_source")
    })
    .tooltip({
        tooltipClass: "ui-state-highlight"
    });
like image 567
yossi Avatar asked May 05 '16 07:05

yossi


People also ask

How to extend autocomplete object in jQuery?

You need to use Jquery widget factory to extend autocomplete object. It is explained in these articles:

Why is the rendermenu function not firing?

Most likely the renderMenu function is not firing because the response () callback receives nothing

What is autocomplete AutoCAD?

Autocomplete. The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are tags for programming languages, give "ja" (for Java or JavaScript) a try. The datasource is a simple JavaScript array, provided to the widget using the source-option.

What is the DataSource of the autocomplete widget?

The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are tags for programming languages, give "ja" (for Java or JavaScript) a try. The datasource is a simple JavaScript array, provided to the widget using the source-option. Want to learn more about the autocomplete widget?


1 Answers

i've never used extensions in that way, and i can't say why it isn't working (it should, i suppose).

Anyway, try with the standard way, on create callback:

this.input = $("<input>")
    .appendTo(this.wrapper)
    .val(value)
    .attr("title", "")
    .addClass("custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left")
    .autocomplete({
        autoFocus: true,
        response: function (event, ui) {
            if (ui.content.length == 0) {
                    ui.content.push({
                        label: "new value: " + $(this).val(),
                        value: $(this).val(),
                        id: 0
                    });
            }
        },
        delay: 0,
        minLength: 0,
        source: $.proxy(this, "_source"),
        create: function() {
            $(this).data('ui-autocomplete')._renderItem  = function (ul, item) {
              return $("<li>")
                .addClass("Please work")
                .attr("data-value", item.value)
                .append(item.label)
                .appendTo(ul);
            };

        }
    })
    .tooltip({
        tooltipClass: "ui-state-highlight"
    });

see this FIDDLE

like image 88
pumpkinzzz Avatar answered Sep 20 '22 20:09

pumpkinzzz