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??

1

2 Answers 2

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

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

2 Comments

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');
if ($("#divPopup")) $("#divPopup").dialog("destroy");
-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");
    }
});

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.