EasyUI Forum
April 29, 2024, 09:46:23 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: onBeforeClose event in dialog  (Read 3427 times)
galcott
Newbie
*
Posts: 39


View Profile
« 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');
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 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;
}
})
Logged
galcott
Newbie
*
Posts: 39


View Profile
« Reply #2 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.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!