PDA

View Full Version : Form submitting combobox text



lucasite
22 Jun 2010, 12:12 PM
Hi,
I have a combo box in my form, and when Im calling form.submit(), the text value of the combo is being posted.
I cant for the life of me find a property to set so that the id value is posted instead.


var myData = [
[1, 'Bank Account'],
[2, 'Savings Account'],
[3, 'Credit Card']
];

// simple array store
var store = new Ext.data.ArrayStore({
fields: ['id', 'name'],
data : myData
});


and my combo:

new Ext.form.ComboBox({
id: "acctype",
name: "accountType",
store: store,
valueField: 'id',
displayField:'name',
editable: false,
typeAhead: true,
mode: 'local',
triggerAction: 'all',
emptyText:'Select an account type...',
selectOnFocus:true
}),


I've set the valuefield property, but its still posts the combo text.
Can anyone see where Im going wrong?

regards

Luca

lucasite
22 Jun 2010, 12:20 PM
oooh,
hiddenName: 'accountTypeValue' is my answer!
doh!

Mark
22 Jun 2010, 12:21 PM
Use "hiddenName"

Jangla
23 Jun 2010, 2:28 AM
I have the same problem but using hiddenName doesn't solve it. If I look at the HTML code, when the user selects a value in the drop down, the hidden field is correct but the instant focus moves away from the combo, the hidden field updates to the displayValue!!!

lucasite
23 Jun 2010, 4:46 AM
Sounds strange, what properties are you setting on your combo box, maybe if you paste it in here, someone might stop an odd property?!

Jangla
23 Jun 2010, 4:50 AM
{
cls : 'x-form-combo x-form-combo-image',
xtype : 'combo',
mode : 'local',
id : 'country-combo',
fieldLabel : 'Country',
triggerAction: 'all',
editable : false,
width : 200,
store : countryStore,
hiddenName : 'country',
valueField : 'code',
displayField : 'name'

}
Having put a break point in the code, it seems that the setValue event is being called twice; once when the user clicks in the combo box and once when the focus is moved away from the combo box. It's this second call in which the value gets updated to the display value.

So for example, selecting 'United Kingdom' in the drop down will correctly put 'UK' in the hidden field but the instant focus moves to another control (or just away from the combo) by clicking anywhere on the screen, setValue is called again and 'United Kingdom' is put into the hidden field.

EDIT: Found the problem!!!! Our grails controller was sticking a "\r" on the end of the field, meaning ExtJS couldn't find the right info when it ran assertValue.

Frustrating, but at least I'll know what to look for next time it happens!