PDA

View Full Version : How to get component object from click event(selected/clicked component in panel)



Periyasamy A
12 Oct 2012, 5:42 AM
var mypanel=Ext.create("Ext.panel.Panel",{
items: [{
xtype: 'textfield', //clicked component
fieldLabel: 'myname'
}, {
xtype: 'textfield',
fieldLabel: 'myname1'
}]

})


mypanel.el.on('click', function(e,el) {

//Here i need to get 'myname' component object and get component config details


});

bulletsoul
12 Oct 2012, 7:12 AM
Do you mean something like this?


mypanel.el.on('click', function(e,el) {

//Here i need to get 'myname' component object and get component config details
Ext.get(el.id);

});

Periyasamy A
12 Oct 2012, 10:02 AM
Ext.get returns an Ext.Element object which is an abstraction of an HTML element object containing utility methods to perform DOM manipulation. It does not retrieve Components (e.g. Panels, Grids, form Fields, etc) by their id.

vietits
12 Oct 2012, 4:44 PM
Try this:


mypanel.el.on('click', function(e,el) {
var cmp = Ext.getCmp( el.id.replace(/-[a-z]+$/i, '') );
console.log(cmp);
}

Periyasamy A
13 Oct 2012, 6:39 AM
how the code return component object without provide any id or itemid for the component ?

vietits
13 Oct 2012, 3:01 PM
The component id will be generated automatically by the framework if it does not exist. It is a good practice to not config id for component, try to use itemId instead.