开发者

How to disable jquery ui combobox?

开发者 https://www.devze.com 2023-04-11 14:12 出处:网络
I use standard code taken from 开发者_运维百科this page and try to disable combobox: $( \"#cbCountry\" ).combobox({ disabled: true });

I use standard code taken from 开发者_运维百科this page and try to disable combobox:

$( "#cbCountry" ).combobox({ disabled: true });

But it is still enabled. What is wrong here?


Easy modification to combobox library to use:

$("#cbCountry").combobox('disable');
$("#cbCountry").combobox('enable');

In your combobox.js file add:

  • in _create: function() add local variable "a" (after var input, a ...).
  • Change input = $("<input>") to input = this.input = $("<input>").
  • Change a = $("<a>") to a = this.a = $("<a>").
  • Insert after destroy:

    disable: function() {
        this.input.prop('disabled',true);
        this.input.autocomplete("disable");
        this.a.button("disable");
    },
    enable: function() {
        this.input.prop('disabled',false);
        this.input.autocomplete("enable");
        this.a.button("enable");
    }
    


    I had to disable the combo box on click of button in my web application. Thanks to the people who have commented here. I was able to figure how to disable and enable the combo box as and when required. The code is as follows.

    The below code is for disabling the combo box

    $("#MyComboboxId").parent().find("input.ui-autocomplete-input").autocomplete("option", "disabled", true).prop("disabled",true);
    $("#MyComboboxId").parent().find("a.ui-button").button("disable");
    

    The above JavaScript code finds the HTML elements for the ID and rest is explained in the above posts.

    The below code is for enabling the combo box

    $("#MyComboboxId").parent().find("input.ui-autocomplete-input").autocomplete("option", "disabled", false).prop("disabled",false);
    $("#MyComboboxId").parent().find("a.ui-button").button("enable");
    


    That code is for initializing a disabled combobox. If you want to disable an existing combobox, use this:

    $("#cbCountry").combobox("option", "disabled", true);
    

    UPDATE

    Combobox is a separate jQuery UI widget, and it seems it does not implement these options. I was able to disable it by finding the text field and button inside the widget, and disabling those:

    $("#cbCountry").closest(".ui-widget").find("input, button" ).prop("disabled", true)
    
  • 0

    精彩评论

    暂无评论...
    验证码 换一张
    取 消

    关注公众号