EasyUI Forum

General Category => General Discussion => Topic started by: eagleeye on April 08, 2016, 07:14:52 AM



Title: How to check if one dialog exists? (Singleton Pattern)
Post by: eagleeye on April 08, 2016, 07:14:52 AM
Hi partners have a nice day, i have one div to show one dialog  it is created fine when is called for first time, but when is called in subsecuent times one error appear .

My question is  How to check if it dialog exists?, if it exists only must be showed and not created .

Code:
<div id="dialog_cambiaPassword"></div>

My function for create the dialog is it:

Code:
function openDialog() {
   
    //var dialog_pass = $("#dialog_cambiaPassword");
   
       var dlg =  $('#dialog_cambiaPassword').dialog({
            title: 'AgendaNet',
            width: 400,
            height: 200,
            closed: true,
            resizable: false,
            href: 'cambiaPassword.html',
            modal: true,
            buttons: [
                {
                    iconCls: 'icon-save',
                    text: 'Grabar',
                    handler: function () {
                        alert('save');
                    }
                },
                {
                    iconCls: 'icon-cancel',
                    text: 'Cancelar',
                    handler: function () {
                        //$('#dialog_cambiaPassword').dialog('close');
                        //$('#dialog_cambiaPassword').dialog('destroy');
                         dlg.dialog('destroy')
                    }
                }
            ]
        });
         $('#dialog_cambiaPassword').dialog('open');
}


Title: Re: How to check if one dialog exists? (Singleton Pattern)
Post by: stworthy on April 09, 2016, 02:07:01 AM
Try this code:
Code:
var dlg = $("#dialog_cambiaPassword");
if (dlg.data('dialog')){ // the dialog has been created
...
} else {
dlg.dialog({
...
})
}


Title: Re: How to check if one dialog exists? (Singleton Pattern)
Post by: eagleeye on April 11, 2016, 06:35:38 AM
Thanks it works fine!!!