2

I have functionality where I dynamically create Dialog. Some time I require Modal or Confirm Dialog

So I created to Function

function createDialogWithOutClose()
{
    jQuery('#divPopup').dialog('destroy');

    var dialog = jQuery('#divPopup').dialog({
        autoOpen: false,
        height: 450,
        width: 650,
        modal: true,
        open: function(event, ui){
            jQuery('body').css('overflow','hidden');
        }

    });

    jQuery('#divPopup').dialog('open');
}

and

function createConfirmDialog(url,params)
{
    jQuery('#divPopup').dialog('destroy');

    var dialog = jQuery('#divPopup').dialog({
        autoOpen: false,
        resizable: false,
        modal: true,
        show: "blind",
        hide: "explode",
        open: function(event, ui){
            jQuery('body').css('overflow','hidden');
        },
        buttons: {
            Ok: function() {
                jQuery( this ).dialog( "close" );
                jQuery.ajax({
                    type: "POST",
                    url: url,
                    data: params
                });
            },
            Cancel: function() {
                jQuery( this ).dialog( "close" );
            }
        }

    });

    jQuery('#divPopup').dialog('open');

}

Problem here is when I give call to this function, It opens previously opened Dialog.

I guess previous instance is not get removed.It doesnt dynamically create Dialog

Any solution??

AliMan
  • 107
  • 2
  • 2
  • 10
  • possible duplicate of [jquery: How to completely remove a dialog on close](http://stackoverflow.com/questions/2864740/jquery-how-to-completely-remove-a-dialog-on-close) – mplungjan Jan 14 '12 at 11:59

2 Answers2

4

Have a look at http://docs.jquery.com/UI/Dialog/dialog#method-destroy

jquery: How to completely remove a dialog on close

http://groups.google.com/group/jquery-ui/browse_thread/thread/4f9804ccb01c1bc8/5b1971d1f0abf1fa?pli=1

Community
  • 1
  • 1
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • I have one more problem, when I create new Dialog it doesn't get div id as we remove the div on closing Due to this it doesn't wrk properly jQuery('#divPopup').dialog('destroy'); – AliMan Jan 16 '12 at 07:55
  • `if ($("#divPopup")) $("#divPopup").dialog("destroy");` – mplungjan Jan 16 '12 at 12:36
-1

Simply use a flag to check dialog state (close/open)

var Open = false;
$('button').click(function () {
    if (!Open) {
        Open = true;
        $(newDiv).dialog({
            close: function (event, ui) {
                Open = false;
            }
        });

    } else {
        alert("Close opened dialog first");
    }
});
Adnan Iqbal
  • 39
  • 1
  • 5