PDA

View Full Version : [INFOREQ] Error on closing window that has been just shown



Greendrake
26 May 2011, 2:23 PM
In 4.0.1, the following code fails due to undefined this.el in the "enable" method in Ext.util.KeyMap (line 22557 in ext-all-debug.js).

Ext.onReady(function() {
new Ext.window.Window({
autoShow: true,
items: {html: 'Blablabla'},
listeners: {
'show': function(w) {
w.close();
}
}
});
});
It works OK if we wait some time after the window gets shown, replacing w.close() with Ext.Function.defer(w.close, 1000, w); But that's not the way it should behave I guess.

Greendrake
26 May 2011, 3:57 PM
OK, I think I've found where the problem is and how to resolve it.

The problem is that in Window, "show" event is called before the afterShow stuff completed. The afterShow method in Window is inherited, and keyMap.enable() is called after the parent method, which fires "show" event.

The solution would be to move the firing of "show" event in Component from afterShow to show:


afterShow: function(animateTarget, cb, scope) {
..........
// me.fireEvent('show', me); <- remove this
},

show: function(animateTarget, cb, scope) {
..........
} else if (this.fireEvent('beforeshow', this) !== false) {
..........
if (this.rendered) {
..........
this.afterShow.apply(this, arguments);
this.fireEvent('show', this); // <- add this
}
}
return this;
}

Greendrake
25 Jun 2011, 10:50 PM
This is not fixed in 4.0.2a. Is it gonna be?

mitchellsimoens
26 Jun 2011, 8:28 AM
This is a timing thing as this small change to the code works:


new Ext.window.Window({
autoShow: true,
items: {html: 'Blablabla'},
listeners: {
'show': {
delay : 100,
fn : function(w) {
w.close();
}
}
}
});

However this is not a permanent fix as different computers may need a higher delay. Not sure why you would want to close it right away though? You could use the "beforeshow" event and return false to cancel the showing or even "beforerender" to cancel the rendering altogether.

Greendrake
27 Jun 2011, 4:50 PM
This is a timing thing ... However this is not a permanent fix as different computers may need a higher delay. Not sure why you would want to close it right away though?
The original task was different and I already have forgotten what it was as the fix I found works well for me :). The example I gave is just a simplest test case reflecting the original problem. What I remember clearly is that I needed an event that would fire when a window is 100% ready for doing anything on it (where closing is not an exception). And the show event did not appear to be acceptable for that purpose until the fix was applied.

Is there another event for window that closing could be performed on without any errors? If we need to wait for something in your solution, what would/could it be? If this is unclear, we have potential inconsistency that should be resolved regardless of the inanity of closing window right away :).