iShah
iShah

Reputation: 149

JQuery UI Combobox Disable

I hope this is not a duplicate question. I have searched enough on Stackoverflow to find an answer my simplest question.

I have a set of radiobox and based on the values of the radiobox I need to disable / enable the user from selecting a from combobox.

Whatever I do, I am not able to make the combobox ReadOnly or Disabled. I use the JQueryUI by directly linking it to http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js. The code to make the normal combobox to the jQuery is as follows:-

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

I tried different methods specified in different places on the net. Nothing seems to work.

Upvotes: 1

Views: 6425

Answers (3)

Yoni Baciu
Yoni Baciu

Reputation: 2707

Boulliou's answer is the better one. Here is another way:

If you do use $.autocomplete then:

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

Upvotes: 0

Domenico
Domenico

Reputation: 208

Easy modification to combobox library to use:

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

In your combobox.js file add:

  1. In _create: function() add local variable "a" (after var input, a, ...).
  2. Change input = $("<input>") to input = this.input = $("<input>").
  3. Change a = $("<a>") to a = this.a = $("<a>").
  4. Insert after destroy function:

--

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");
}

Upvotes: 3

sdespont
sdespont

Reputation: 14025

I have just checked, and you right, disable a combobox is more complex than we could think.

So, I made a fiddle for you that you can find here : http://jsfiddle.net/S77xa/61/

Upvotes: 0

Related Questions