PDA

View Full Version : Problem getting a single field of the form in the button handler



steffenk
24 Jul 2009, 8:30 AM
Hi,

i have a problem accessing a form field in the button handler.
Hier is the pseudocode:


var form = new Ext.FormPanel({
width: 600,
height: 400,
items: [{
xtype: 'textfield',
fieldLabel: 'Any Textfield',
name: 'any',,
value: 'any Text',
ref: '../any'
}, {
xtype: 'colorpalette',
fieldLabel: 'The Color Palette',
name: 'pal',
ref: '../pal'
}],
buttons:[{
text:"Values",
handler: function(btn){
// try to get access to field "any"
var v = btn.ctOwner.any.getValue(); //doesn't work'
}
}],
...
});

how can i access a field at this position?

tryanDLS
24 Jul 2009, 9:36 AM
If you give the fields ids instead of/in addition to name


btn.ownerCt.findById('any');
btn.ownerCt.find('name', 'any'); // might work, may be slow for big structures


You should also be able to find directly in the items collection, which should be faster than looking for components in the parent's structure e.g

btn.ownerCt.items.find..

steffenk
24 Jul 2009, 9:56 AM
Hi,

even if i use id in field,

btn.ownerCt.findById('idOfField')
returns NULL

But with id i can use

Ext.getCmp('idOfField')

Ok, so i'm able to access it now. But i still puzzled about this problem. Using ref means, it's available only after render? I thought this is a nice shortcut for accessing fields.

thx for the help!