Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placeholder opens jQuery UI autocomplete combobox on page load (IE10)

I'm using jQuery UI autocomplete combobox widget. When i add placeholders on my comboboxes, the autocomplete boxes are opened by default.

This occurs only on IE10 and later.

This is my code :

 _create: function () {
            this.wrapper = $("<span>")
            .addClass("custom-combobox")
            .insertAfter(this.element);
            this.element.hide();
            this._createAutocomplete();
            this._createShowAllButton(); 
            this.input.attr("placeholder", this.element.attr('placeholder'));
        },
like image 405
Samet Avatar asked Jan 24 '15 14:01

Samet


1 Answers

We noticed that the issue was being solved by actually focusing the comboboxes.

Once the combobox is focused, the autocomplete box disappeared and it remained that way when the combobox lost focus.

So, our solution was a bit hack-ish, we added a .focus() followed by a .blur() :

 _create: function () {
            this.wrapper = $("<span>")
            .addClass("custom-combobox")
            .insertAfter(this.element);
            this.element.hide();
            this._createAutocomplete();
            this._createShowAllButton(); 
            this.input.attr("placeholder", this.element.attr('placeholder'));

            this.input.focus().blur();
          //^^^^^^^^^^^^^^^^^^^^^^^^^^ Voila!
        },
like image 125
mehmetseckin Avatar answered Nov 14 '22 23:11

mehmetseckin