-
6 Feb 2008 3:27 PM #1
SOLVED: Window beforehide problem
SOLVED: Window beforehide problem
I have an issue with a Window. I am trying to intercept the hide event. This works as hoped:
And stops the hide event. But I would like to do this:Code:win.on('beforehide', function() { if(confirm("Are you sure?")) return true; else return false; });
And it does not work (always continues with the hide).Code:win.on('beforehide', function() { Ext.MessageBox.confirm('Close', 'You may have unsaved changes. Continue?', function(btn) { if(btn=='yes') return true; else return false; }); });
I suspect this is because the MessageBox has its own hide event and the win gets confused. Is there a way to workaround?
Thanks!Last edited by JeffBurr; 6 Feb 2008 at 6:06 PM. Reason: Solved
-
6 Feb 2008 3:57 PM #2
It's because the MessageBox doesn't wait for a response.
Try this:
Code:Ext.Window.prototype.forceHide = function(animateTarget) { this.hidden = true; if (animateTarget !== undefined) this.setAnimateTarget(animateTarget); if (!this.animateTarget) { this.el.hide(); this.afterHide(); } else this.animHide(); }; win.on('beforehide', function() { Ext.MessageBox.confirm('Close', 'You may have unsaved changes. Continue?', function(btn) { if(btn=='yes') win.forceHide(); }); return false; //always return false to wait for the response. } );
-
6 Feb 2008 6:08 PM #3
Thank You!
Thank You!
I didn't intend to submit this as a "bug". I guess I shouldn't drink and post!
Anyway, thanks for the solution - works perfectly.
-
14 Mar 2008 12:28 AM #4
Great solution.. big thanks evant!
-
3 Aug 2009 7:21 AM #5
Found this today and it works great.
However, I am using modal windows, so in the event that anyone else is, you just need to add the following to the forceHide function. Otherwise the page stays masked, even though the window is closed.
Code:if(this.modal){ this.mask.hide(); Ext.getBody().removeClass('x-body-masked'); }
Thanks,
Jon
-
3 Aug 2009 7:53 AM #6
Easier is
Code:win.on('beforehide', function() { Ext.MessageBox.confirm('Close', 'You may have unsaved changes. Continue?', function(btn) { if(btn=='yes') { win.suspendEvents(); win.hide(); // This cannot be vetoed because no events will be fired. win.resumeEvents(); } }); return false; //always return false to veto the hide. });Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642


Reply With Quote
