0

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.

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.