EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: glarsen on June 09, 2014, 01:49:22 PM



Title: Confirmation dialog on panel onBeforeClose
Post by: glarsen on June 09, 2014, 01:49:22 PM
Would like the get confirmation from the user to close a window.  When I use the async messager dialog in the onBeforeClose event the window closes as soon as the dialog appears.

What's the best way to program around this? 

Thanks,
gary


Title: Re: Confirmation dialog on panel onBeforeClose
Post by: jarry on June 09, 2014, 06:31:37 PM
All the $.messager functions work in async mode. This means that the user can't block it before doing any more. To make the confirm message window works like a native confirm window in 'onBeforeClose' event, please try the code below:
Code:
$('#win').window({
  onBeforeClose:function(){
    var p = $(this);
    $.messager.confirm('Confirm','Are you sure you want to close?',function(r){
      if (r){
        var opts = p.panel('options');
        var onBeforeClose = opts.onBeforeClose;
        opts.onBeforeClose = function(){};
        p.panel('close');
        opts.onBeforeClose = onBeforeClose;
      }
    });
    return false;
  }
})