PDA

View Full Version : Before Closing the Ext.Window display a confirmation Message



atul.sachan@capgemini.com
8 Oct 2012, 1:53 AM
I am opening a Ext.window and before closing the window i need to display a confirmation message but it is closed immediately on click of close button.
code:
beforeclose : function(){
Ext.Msg.alert('Name', 'Please enter your name:', function(btn, text){
if (btn == 'ok'){
return true;
}
else
return false;
});
}

vietits
8 Oct 2012, 2:17 AM
Ext.Msg.alert() is nonblocking and will run asynchronously. It means that the execution of beforeclose event handler will continue after calling Ext.Msg.alert(). With your code, beforeclose event handler won't return false so it does not stop closing window.

atul.sachan@capgemini.com
8 Oct 2012, 2:27 AM
Yes i agree with you, but is there any way to stop closing the window ? or any other solution to achieve this.

a.premkumar
8 Oct 2012, 3:10 AM
You can try overriding the 'close' event instead of 'beforeclose'. That would help to suspend close and show a alert or prompt or what ever you wish,

Regards,
Premkumar. A

atul.sachan@capgemini.com
8 Oct 2012, 3:14 AM
Close event will be trigger immediately after closing the window but i wanted to close the after selecting an option in msg box.

a.premkumar
8 Oct 2012, 3:39 AM
Close event will be trigger immediately after closing the window but i wanted to close the after selecting an option in msg box.

Overriding 'close' event means user defining his own way of operations before, during or after the close event occur. It won't trigger immediately before as you afraid. I have worked on it. Try that and if it doesn't work, then I might suggest you some other way.

Regards,
Premkumar. A

webfriend13
8 Oct 2012, 3:44 AM
HI Atul,

You can use javascript's confirmation box on beforeclose event of the window.



beforeCls: function (panel, eOpts) {
alert('entered');
// This is asyn :(
// Ext.Msg.confirm('Title', 'Message', function (button) {
// if (button === 'yes') {
// return true;
// } else {
// return false;
// }
// });
var r = confirm("Press a button");
if (r == true) {
return true;
}
else {
return false;
//. Return false from to stop the close event being fired
}
},

vietits
8 Oct 2012, 4:40 AM
Below is my solution to use Ext.Msg.alert():


beforeclose: function(){
var me = this;
if(!me.askForConfirm){
me.askForConfirm = true;
Ext.Msg.alert('Confirm', 'Do you really want to close window?', function(btn, text){
if (btn == 'ok'){
me.close();
}
delete me.askForConfirm;
});
return false;
}
return true;
}