View Full Version : Setting a combo value and hidden value

8 Nov 2010, 9:18 AM
EDIT | Just to clarify the issue I am having. Basically i need the ability to update both the combo value and it's hidden value, as the value is the customer name and hidden value is the customer ID - which is what I need posted back to server - while retaining the customer name in the listbox or text field. I thought setValue() passing the customer name would automatically change the hiddenValue to the selected customer ID but this doesn't seem to be the case???

--- END OF EDIT ---

I have two combos which must syncronize with each other. When one changes it updates the other with relevent info.

Problem is, when I call setValue() on the combo (from within the select of the other) and I pass the customer name, when I submit, the customer name is sent to server but the PHp scripts are implemented to accept customer ID's.

When I select the customer name from the list, the ID gets submitted, but it appears using setValue() does not have this affect.

I have tried using selectAsValue() but this doesn't seem to match in the combo so it's text remains blank. I am using a custom XTemplate to include the region of a customer rendered in light grey. I wonder if this is causing the customer name not to match???

Is there a way I can set the combo hiddenValue as well so when the form is submitted the customer ID is sent to the server not the name?

Passing the customer ID to setValue() causes the ID to show instead of the customer name, which is undesired.


8 Nov 2010, 10:09 AM
Go find the record in the store where the value is what you want, pull the id and combo.setValue on the id.

8 Nov 2010, 11:28 AM

I already have the ID and the customer name, but I need to set the combobox to display the customer name and the hiddenValue to ID, otherwise when I POST the customer name populates the id_customer field and thus breaks the server script.

My comboboxes all use a displayValue (Customer Name) and hiddenValue (Customer ID). I use the customer ID on the server to quickly lookup required details. However when I set the combo with setValue() if I assign the customer name, then the server script fails (I do not wish to perform an ID lookup on the server) and if i assign the customer ID - the user suffers because 3665 means absolutely nothing to an end user, but ACE HARDWARE means something.

Is there a way to set the hiddenValue and displayValue???


8 Nov 2010, 11:49 AM


8 Nov 2010, 12:43 PM
Cant you take your combo, linked to a store, and specify the id as the value, but the customer name as the display:

name : 'orgName'
,valueField : 'id'
,displayField : 'name'

I'm sure we have different use cases here, since I'm not setting hiddenValue, but on my app, the user can see the customer name in the dropdown, but the value passed is id, so maybe this will help?

Not sure...


8 Nov 2010, 1:36 PM
I think I have done that:



fieldLabel: 'Customer',
anchor: '100%',

id: 'id_combo_customer',

value: customer,

queryParam: 'customer',
hiddenName: 'id_customer',
hiddenValue: id_customer,

minListWidth: 320,

minChars: 0,

allowBlank: false,
forceSelection: true,
triggerAction: 'all',
selectOnFocus: true,

valueField: 'id_primary',
displayField: 'name',

tpl: new Ext.XTemplate(
'<tpl for=".">',
'<div class="x-combo-list-item">{name} <span style="font-size: 7pt; color: darkgrey">{city}</span></div>',

store: new Ext.data.ArrayStore({
fields:[{name: 'id_primary', mapping: 'id_primary'}, {name: 'name', mapping: 'name'},{name: 'city', mapping: 'city'}],
proxy: new Ext.data.HttpProxy({
url: 'services/index.php/application/customer/list'

I'm not sure what I am missing :(


8 Nov 2010, 6:12 PM
1. Why are you giving it an id? That's usually not necessary, and if you spawn two components with the same id, prepare for a bad day.

2. Are you trying to give it an initial value before it's even created? If yes, then you can hand it a value property, otherwise remove that.

3. There is no hiddenValue property that I'm aware of.

4. Are you meaning to set "editable: false" where your setting forceSelection: true?

5. You must declare a mode config. If you want to make it load the first time it's opened, give it mode: 'remote'. mode: 'local' means you'll have to programatically load the store to fill the list.

6. Your template's cool, nice work, TY :)

7. Your field definitions. No need for a mapping, though you should probably add a type for each one (string, int, boolean, date)

8. Seems to me you'd be better off using a JsonStore, maybe you simplified it for purposes of pasting it, IDK. I think this is causing you problems, it could be that I'm misunderstanding your problem and you know better than me, thats ok.

9. Tested. This works:

var store = testCombo.store;
if(Ext.isDefined(store) && Ext.isDefined(store.getCount) && store.getCount() > 0) {

Please use the code markers when you paste code so we can read it easier. (Located on the reply toolbar)

Hope that helped.