PDA

View Full Version : setting a combobox's displayfield by a value



pirusira
20 Jul 2010, 8:32 PM
Hello All.

The following is my combobox.


var companyListCombo = new Ext.form.ComboBox({
id: 'companyListCombo',
fieldLabel: 'company',
store: companyListForAddUser,
displayField:'companyName',
valueField:'companyCode',
hiddenName: 'companyCode',
typeAhead: true,
mode: 'remote',
triggerAction: 'all',
selectOnFocus:true,
editable: false
});

I want to set the displayfield by a value dynamically.


var addUserFormOb = addUserForm.getForm();
addUserFormOb.findField('companyCode').setValue(selectedCompanyCode);

This displays just a code like this : '1000', but it has to display the 'companyName' by the code.

If user view the combobox after click a row of a grid which has a companyCode, then the combobox has to display a companyName by the companyCode value, and then if user submit it, it has to submit the companyCode not companyName.

How do I do this?

Thanks in advance.
Stan

Mark
20 Jul 2010, 10:32 PM
Are you sure that the combolist is already loaded before you set the value?

pirusira
20 Jul 2010, 10:36 PM
No, that's why I asked.
How can I load the combolist and select the field by the value?

Mark
21 Jul 2010, 7:19 AM
Try to add "autoLoad:true" to the config of the Combobox, then set the value:


myCombobox.setValue(valueField); Since I was running into troubles with "hiddenName" some month ago I use instead :
"myCombobox.getValue()" to submit the valueField and
"myCombobox.el.dom.value" to submit displayField

Hope it helps.

pirusira
21 Jul 2010, 4:27 PM
Thank you for the reply&your PM, but I don't quite understand.

What's the valueField in the code? :

myCombobox.setValue(valueField);

Mark
21 Jul 2010, 11:52 PM
What's the valueField in the code? Sorry, that was unhandy, its only a placeholder for the var which you want to set as value in your case the same as "selectedCompanyCode".