EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: galcott on September 28, 2020, 08:02:09 AM



Title: onBeforeClose event in dialog
Post by: galcott on September 28, 2020, 08:02:09 AM
I have a dialog and I would like the user to confirm when they try to close it. In the onBeforeClose event I call a function to display a confirmation dialog and return the result. However, the dialog always closes immediately and then the confirmation is shown after it closes! I have tried several ways to show the confirmation dialog - native JS confirm, your messager, and another library to display confirmations. The same result occurs no matter how I do it. I have also tried putting the onBeforeClose code in the data-options, which makes no difference. So what is the problem here and how do I fix it?
Code:
  
// ConfirmClose is the function where I ask for the confirmation, trying the different methods mentioned above
$('#dlgDataEntry').dialog({onBeforeClose: function() { return(ConfirmClose()) }}); //
$('#dlgDataEntry').dialog('open');


Title: Re: onBeforeClose event in dialog
Post by: jarry on September 28, 2020, 08:19:09 PM
Please refer to the code below:
Code:
$('#dlg').dialog({
enableClosed: false,
onBeforeClose: function(){
var dlg = $(this);
var opts = dlg.dialog('options');
if (opts.enableClosed){
return true;
}
$.messager.confirm({
title: 'Confirm',
msg: 'Are you confirm this?',
fn: function(r){
if (r){
opts.enableClosed = true;
dlg.dialog('close');
setTimeout(function(){
opts.enableClosed = false;
},400)
}
}
})
return false;
}
})


Title: Re: onBeforeClose event in dialog
Post by: galcott on September 29, 2020, 01:51:03 PM
This code doesn't make sense to me. Why is it even necessary? And what is the enableClosed option? I can't find this anywhere in the documentation. It seems like the onBeforeClose event is not working as it should. Please explain.