I am extending a window in Ext 3.3 that gets called in many places, and has many extensions of itself. There is a configurable field for this window. When this field is null, or contains no items, I'd like to display an error message and not continue to display the window. This is how I'm approaching it:
data: null,
initComponent: function() {
if(data && data.length > 0) {
...
$this.superclass.initComponent.apply(this, arguments);
} else {
Ext.MessageBox.alert(...)
}
}
is this an appropriate way/place to do this? I've considered validating when the component is called, but considering there are so many places this will happen, I don't want much redundant code. Mainly my confusion lies in being unclear about what happens before and after initComponent, or if there's a simple readable way to eliminate the component call altogether.
EDIT: the above is definitely wrong. i thought it was working only because an error was being thrown and not rendering the window.
In my opinion, beforerender
event will be a good place:
when you will return false, the component will not render.
listeners: {
beforerender: function(){
if(!data || data.length == 0) {
Ext.MessageBox.alert(...);
return false;
}
}
}