PDA

View Full Version : Set FormPanel TextBox Value



rehanazher
6 Aug 2009, 12:19 AM
Hi,

I am unable to set the value of text field on a form using .setValue or .setRawValue.
Below is my code for my FormPanel:



var customerInfoPanel = new Ext.FormPanel({
title: "Customer Information",
collapsible: true,
frame:true,
animCollapse: true,
defaultType:'textfield',
labelAlign : 'right',
labelWidth: 120,
monitorValid:true,
items:[
{
fieldLabel: 'Customer Name',
id: 'name1',
name: 'name',
labelStyle: 'font-weight:bolder;',
width: 400,
},{
xtype: 'fieldset',
title: "Priamry Point of Contact[PPOC]",
collapsible: true,
autoHeight:true,
labelWidth: 105,
defaultType:'textfield',
width: 540,
items:[
{
fieldLabel: 'PPOC',
id: 'ppoc',
labelStyle: 'font-weight:bolder;',
width:400
},{
fieldLabel: 'Contact',
id: 'ppocContact',
labelStyle: 'font-weight:bolder;',
width: 400
},{
fieldLabel: 'Email',
labelStyle: 'font-weight:bolder;',
id: 'ppocEmail',
width: 400

}
]
}
]
});
I am trying to set the form field values during load event of a datastore:



var dscustomerByid = new Ext.data.Store({
autoDestroy: true,
reader: new Ext.data.JsonReader({
fields: ['value', 'customerName', 'ppoc','ppocEmail','ppocContact'],
root: 'rows'
}),
proxy: new Ext.data.HttpProxy({
url: 'include/getCustomerById.php'
})
});
dscustomerByid.load({params:{id1: rId}});
dscustomerByid.on("load", function() {
myResult = dscustomerByid.getAt(0);
var a =Ext.getCmp('name');
customerInfoPanel.getForm().findField('name').setValue=myResult.get('customerName'); //no action
alert(myResult.get('customerName')); //this returns my field valye
});

rId is a variable containg a particular customerID;
I am just a beginners, so please excuse if I am asking some thing really basic.


Thanks and best regards,

rehanazher
6 Aug 2009, 12:25 AM
Admin,

Sorry posted in wrong forum, can someone please move it to Ext3.0 Help Forum

Condor
6 Aug 2009, 12:28 AM
setValue is a method, not a property!


customerInfoPanel.getForm().findField('name').setValue(myResult.get('customerName'));

(and I don't know if this is relevant, but this only works after the form is rendered)

rehanazher
6 Aug 2009, 12:40 AM
thanks Condor, it worked.

I think I am tired (:| today, i was just seeing the example code it was exactly the way you told but was writing the code differently.

one More related question, since this one is working, should following work or not:



var a=Ext.getCmp('name1');
a.setValue("world");

name1 is id of txtfield in a FormPanel.I tried but not working.

Condor
6 Aug 2009, 12:45 AM
That should work. Are you sure you are not doing anything wrong (you did create the form first?).