PDA

View Full Version : Set value of Combo box on Form Load



nitesh35103
10 Jun 2009, 2:44 AM
Hi,

I have got a combo box


new Ext.form.ComboBox({
fieldLabel: 'Sector',name:'companySector',
store: new Ext.data.SimpleStore({
fields: ['code', 'sector'],
data : Ext.exampledata.sector // from sector.js
}),
valueField:'code',displayField:'sector',typeAhead: true,mode: 'local',
triggerAction: 'all',emptyText:'Select ...',selectOnFocus:true,
anchor:'95%'
})I want to set the value of Combo box on Form.load. Can someone tell me how to load this combo box on form load.

For text field I am doing
form.getForm().findField("companyName").setValue("ABCJ Limited");
For Combo box, how should I load some value ??

Animal
10 Jun 2009, 2:49 AM
Set the value to the code.

nitesh35103
10 Jun 2009, 2:57 AM
Thanks Animal,
I am not getting it,


form.getForm().findField("companySector").setValue();


Where I should make changes ??

Animal
10 Jun 2009, 2:59 AM
You have code and sector as two fields.

Set the value as the code.

nitesh35103
10 Jun 2009, 3:09 AM
Thanks Animal,
got it!!

Vicho
6 Jul 2009, 11:17 AM
nitesh35103

I have the same problem, but I did not understand it at all.
Could you please put the complete code here.


Thanks in advance

nitesh35103
6 Jul 2009, 2:35 PM
Hi Vicho,

new Ext.form.ComboBox({
fieldLabel: 'Country',name:'companyCountry',
store: new Ext.data.SimpleStore({
fields: ['abbr', 'state'],
data : Ext.exampledata.states // from states.js
}),
valueField:'abbr',displayField:'state',typeAhead: true,mode: 'local',
triggerAction: 'all',emptyText:'Select ...',selectOnFocus:true,
anchor:'95%'
})

setValue

form.getForm().findField("companyCountry").setValue("UK");
getValue

var companyCountry = (!form.getForm().findField("companyCountry").getValue())? "--" :form.getForm().findField("companyCountry").getValue();

Store

Ext.exampledata.states = [...,...,..., ['UK', 'UNITED KINGDOM'],...]

Vicho
7 Jul 2009, 5:36 AM
Hi nitesh35103, thanks a lot !!

At last!! this works!!! jeje :))

but....

the only way this works for me is put the "setValue" in a listeners of the "load" event of the "store" of the combobox. :-?

Sorry for my English... I am from Chile.


and thanks again! :D:D

zillabyte
12 Feb 2011, 9:19 AM
I have a FormPanel that uses a combo box. I'm able to populate the box with values. However when I retrieve the values from the server and populate the hiddenId the combo box loses all the values. Not sure why. Can someone tell me what I'm doing wrong?

var cust_type_store = new Ext.data.SimpleStore({
fields: ['id', 'cust_type'],
data: [['1', 'Customer'], ['2', 'Friend'], ['3', 'Family']]
});

// in form config

}, {
xtype: 'combo',
name: 'cboCustomerType',
fieldLabel: 'Type',
valueField: 'id',
displayField: 'cust_type',
hiddenName: 'CustomerType',
mode: 'local',
minChars: 0,
store: cust_type_store,
width: 120
}, {
xtype: 'hidden',
name: 'CustomerKey'
}, {
xtype: 'hidden',
name: 'CustomerType'
}

//-- populate

formfrm.findField('CustomerType').setValue(rs.CustomerType);
frm.findField('CustomerKey').setValue(rs.CustomerKey);

zachext
12 Feb 2011, 12:48 PM
When you specify a hiddenName for a combo, ext automatically generates a hidden field of the name specified and manages the value within it.

Try removing this:


, {
xtype: 'hidden',
name: 'CustomerType'
}

and then populate with this:



yourform.findField('cboCustomerType').setValue(rs.CustomerType);

zillabyte
12 Feb 2011, 5:57 PM
Thanks for your reply. I did find the information on the hiddenfield behavior in the class browser. I not sure exactly what I did that got this working, though. I still kept the Hidden name but added a Hidden id and a triggerActions setting and it worked.

hiddenName: 'CustomerType',
hiddenId: 'CustomerType',triggerAction: 'all',
Having all this configured makes it work. Still in the noob stages with ExtJS so finding where all the docs are located and browsing the forum takes a lot of time. Appreciate your reply.