Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i show a blank option in jquery autocomplete?

I am using a jquery autocomplete with combobox nabled. I want to show an empty option however whenever I set the value of my initial selection to an empty string it is not shown in the combobox.

The item is present it just contains no height.

Is it possible to have a blank option on an autocomplete combobox ?

like image 393
BentOnCoding Avatar asked Jul 15 '11 18:07

BentOnCoding


2 Answers

$("#ctrl").autocomplete({
    source: [ "\u00A0", "One", "Two" ]
});
like image 98
SergeyA Avatar answered Sep 27 '22 01:09

SergeyA


So we figured out the solution. You need to work with the _renderItem method.

input.data("autocomplete")._renderItem = function(ul, item) {
    var listItem;
    if (item.label == "<strong></strong>") {
        listItem = $("<li></li>")
              .data("item.autocomplete", item)
              .append("<a><br></a>")
              .appendTo(ul);
    } else {
        listItem = $("<li></li>")
              .data("item.autocomplete", item)
              .append("<a>" + item.label + "</a>")
              .appendTo(ul);
    }

    return listItem;
};

Take note that you must have a blank string item in your initial list for this to work.

like image 25
BentOnCoding Avatar answered Sep 27 '22 01:09

BentOnCoding