JQuery-ui dialog box, "toggle" modal option not working

Possibly changing jquery ui dialog modal mode dynamically?

I made a working example: http://jsfiddle.net/LXB2Y/ and it looks like it doesn't work.

 $( this ).dialog("option","modal",false);



source to share

3 answers

It looks like the dialog won't reflect the changes while it's open, but the changes will take effect. To show the changes, you can close and then immediately open the dialog. This may not be the best solution.

                $( this ).dialog("option","modal",true)





If you want to change the options in a dialog box, you need to do so before opening it. Otherwise, you will need to interact with the components of the dialog, such as overlaying with your own code after opening it.


/* initialize a dialog*/
$('#dialog').dialog({autoOpen:false, modal:true});

/* open a dialog from a click handler and change options*/  
    /* change original modal option*/                         
    $('#dialog').dialog('option', 'modal', false);
    /* change title based on text of "myButton"*/
    $('#dialog').dialog('option', 'title', $(this).text())

    /* options have been changed, open dialog now */




Still doesn't work with jQuery 1.11. You can just add the overlay manually, but if you want to go from modal to modal dialog:

$("#dialog").dialog("widget").before("<div class='ui-widget-overlay ui-front'></div>");


Remove the overlay accordingly if you want to switch from modal to modeless dialog.



All Articles