PDA

View Full Version : Getting HTMLElement using Ext.fly() failing... any other way?



imnilesh
25 Jun 2009, 11:32 PM
Following code:

var item = new Ext.Toolbar.TextItem(' ');
Ext.fly(item.el).addClass('test-class');

was working fine for Ext 2 but now in Ext 3.0, item.el is not returning the HTMLElement.
Gone through the documentation of Ext 3.0, could not find the API to get the HTMLElement. I tried using the new config option 'autoEl', but it also did not worked for me.

Any way to get the HTMLElement?

Thanks in advance.

Animal
25 Jun 2009, 11:41 PM
It's not rendered just by creating it.

Anyway, http://extjs.com/deploy/ext-3.0-rc2/docs/?class=Ext.Toolbar.TextItem&member=cls

imnilesh
26 Jun 2009, 3:23 AM
Yes, it seems HTMLElement will not be available till the component is rendered so we can't use 'item.getEl()'. I added the class after the item gets rendered in the toolbar:

var item = new Ext.Toolbar.TextItem(' ');
item.on('afterrender', addClassMethod, tbar);
this.myItem = item;

function addClassMethod(tbar){
var item = this.myItem;
Ext.fly(item.el).addClass('custom-class');
}

Thanks Animal.

Animal
26 Jun 2009, 3:47 AM
you didn't read the docs that I linked to then?

imnilesh
26 Jun 2009, 4:05 AM
Ohh I thought you directed to TextItem Documentation, I did not figure out you directed to 'cls' config option.

var item = new Ext.Toolbar.TextItem({
text: ' ', cls: 'custom-class'
});

solution looks pretty straight forward now and it works for me.

Thanks.