PDA

View Full Version : problem accessing items in formPanel



alexv55
22 Dec 2010, 4:18 PM
I am very new to ext js and experimenting with formPanel from tutorial link. I have the following code and try to display a property of an element of 'items' array It is a text field. It gives items[1] undefined message.

Ext.onReady(function() {

var simple = new Ext.form.FormPanel({

standardSubmit: true,

frame:true,
title: 'Register',

width: 350,
defaults: {width: 230},
defaultType: 'textfield',
items: [{
fieldLabel: 'Username',
name: 'username',
allowBlank:false
},
{
fieldLabel: 'Password',
name: 'password',
allowBlank:false,
inputType: 'password'
}

],
buttons: [{
text: 'Submit',
handler: function() {
simple.getForm().getEl().dom.action = 'test.php';
simple.getForm().getEl().dom.method = 'POST';
simple.getForm().submit();
}
}]

}); // formpanel.



simple.render('mytraditionalform');
alert(simple.items[1].fieldLabel);


});

rkaat
22 Dec 2010, 11:11 PM
Use :


alert(simple.items.items[1].fieldLabel);

alexv55
23 Dec 2010, 8:20 AM
Thanks for your help, it works. But conceptually I don't understand why items.items[x]. items is a property of formpanel which is an array so it seems that simple.items[1] would give me the second element of the array and I should then be able to refer to its property . Where is items.items[x] coming from.There is nothing in the api reference that points to that.

Thanks.

Screamy
23 Dec 2010, 4:17 PM
Also consider the user of the ref attribute on each of your FormPanel's fields:



items: [{
fieldLabel: 'Username',
name: 'username',
allowBlank:false,
ref: 'user'
},{
fieldLabel: 'Password',
name: 'password',
allowBlank:false,
inputType: 'password'
ref: 'pword'
}
You can then do things like:



var u = simple.user.getValue();
var p = simple.pword.getValue();

Condor
24 Dec 2010, 1:16 AM
Or:

var username = formPanel.getForm().findField('username').getValue();
(but the 'ref' method is faster)