Prince
Prince

Reputation: 1290

Disable jquery ui dialog

I have three buttons: first open, second disable, and third enable. When user click on disable button then jquery ui dialog should be disabled and not open on click on open button. After that, if user click on enable then dialog should be enabled and open on open dialog click.

example:-

code:-

$(function() {
    $( "#dialog" ).dialog({
      autoOpen: false,
      show: {
        effect: "blind",
        duration: 1000
      },
      hide: {
        effect: "explode",
        duration: 1000
      }
    });

    $( "#opener" ).click(function() {
      $( "#dialog" ).dialog( "open" );
    });
  });

Any help should be appreciated.

Upvotes: 0

Views: 83

Answers (3)

user3040830
user3040830

Reputation:

Hi Prince You can set a global variable with on the button clicks and can handle the enabling and disabling of the dialog based on that global variable like below:

  var isDisabled=false;
         $( "#opener" ).click(function() {
              if(!isDisabled)
                 $( "#dialog" ).dialog( "open" );
          });
         $( "#enabler" ).click(function() {
                 isDisabled=true; 
          });
         $( "#disablerr" ).click(function() {
                 isDisabled=false;
          });

Upvotes: 0

Barmar
Barmar

Reputation: 780673

Use a variable to keep track of whether the dialog is enabled.

var dialog_enabled = true;

$("#opener").click(function () {
    if (dialog_enabled) {
        $("#dialog").dialog("open");
    }
});

$("#disable_dialog").click(function() {
    dialog_enabled = false;
});
$("#enable_dialog").click(function() {
    dialog_enabled = true;
});

DEMO

Upvotes: 0

Dirgh
Dirgh

Reputation: 507

Hope this helps.

var isEnable=1;
     $( "#opener" ).click(function() {
          if(isEnable)
             $( "#dialog" ).dialog( "open" );
      });
     $( "#enabler" ).click(function() {
             isEnable=1; 
      });
     $( "#disablerr" ).click(function() {
             isEnable=0;
      });

Other way is disable/enable button using jquery but I think this is better option if you do not have css disable effect.

Upvotes: 1

Related Questions