PDA

View Full Version : Problem with 'beforerender' event



Arunair
15 Dec 2014, 3:46 AM
Consider the random class below.
I want to render its child items depending on some condition.
For that in beforerender I return false based on the condition.

But, if the beforerender function returns false, complete container is not rendered.
(i.e. Other item (Text2) is not rendered)

Ext.define('ClassA',
{
extend : "Ext.container.Container",
xtype: 'a1', // TabPanel itself has no title
itemId: 'a1',
border : false,
arialRole : 'region',

// First tab active by default
layout :
{
type :'vbox',

},
items:[
{
xtype: 'button',
text : 'Text',
itemId : 'btNotifyBar',

listeners:
{
beforerender : function(a, optws)
{

// Some Condition
if(app.globals.data.get(1)==1)
return true;
else
return false;
}
}
},
{

xtype: 'button',
text : 'Text2',
itemId : 'item2'


}

]
});

lumberjack
17 Dec 2014, 9:56 AM
I am not able to reproduce this behavior.

Regards,
Brian

https://fiddle.sencha.com/#fiddle/f89
f89

Arunair
18 Dec 2014, 2:01 AM
Ext.application({
name : 'Fiddle',


launch : function() {
new Ext.container.Container({
renderTo: Ext.getBody(),
items: [

{

xtype : 'a1'
},
{
xtype: 'button',
text: 'Button 3'
},
, {
xtype: 'button',
text: 'Button 2'
}]
});
}
});








Ext.define('ClassA',
{
extend : "Ext.container.Container",
xtype: 'a1', // TabPanel itself has no title
itemId: 'a1',
border : false,
arialRole : 'region',


// First tab active by default
layout :
{
type :'vbox',

},
items:[
{
xtype: 'button',
text : 'Text',
itemId : 'btNotifyBar',

listeners:
{
beforerender : function(a, optws)
{
// try changing to true to see both text..
return false;
}
}
},
{
xtype: 'button',
text : 'Text2',
itemId : 'item2'

}


]
});

lumberjack
18 Dec 2014, 6:15 AM
A better approach would be to configure the hidden property of whatever component to true, and then listen for the render event to toggle visibility of the component.

Regards,
Brian

https://fiddle.sencha.com/#fiddle/f89
f89