PDA

View Full Version : Extended Combo submitting displayField instead of valueField



JoelCool
5 Aug 2009, 7:37 PM
I have a slightly customized combo box I use for multiple fields in a form as follows:

// Boolean Store - Extends SimpleStore
var BooleanStore = new Ext.data.SimpleStore({
fields: ['field','display'],
data: [[1,'Yes'],[0,'No']]
});
// Boolean Combo - Extends ComboBox
BooleanCombo = Ext.extend(Ext.form.ComboBox, {
constructor: function(config) {
Ext.apply(this, {
store : BooleanStore,
displayField : 'display',
valueField : 'field',
mode : 'local',
triggerAction : 'all',
editable : false,
disabled : true
});
BooleanCombo.superclass.constructor.apply(this, arguments);
}
});


I instantiate it in my form by:
new BooleanCombo({id:'prop-pool',fieldLabel:'Pool'})

When I load data into the form I set the value to 0 or 1 and it displays correctly as 'No' or 'Yes'. However, when I submit (after setting disabled to false) the form the values sent to the back end are the displayField data of 'No' or 'Yes' when I would expect the valueField of 0 or 1 to be submitted.

Is this expected or am I doing something wrong?

Animal
5 Aug 2009, 9:29 PM
READ the APi docs.

WYSIWYG.

You can SEE that there is an input field which contains the displayField value.

It's named the name you give it.

So it gets submitted.

If you want some hidden field to contain the valueField, you must tell it.

And the API docs tell you this, and tell you how.

This is the 1553263rd time this has been asked, and nobody ever looks at the FAQ!

http://extjs.com/learn/Ext_FAQ_ComboBox#Form_submits_displayField_instead_of_valueField

JoelCool
8 Aug 2009, 10:04 AM
Ah, my bad. I obviously had the same expectation that the other 1553262 had, that it would behave like an html SELECT field, which posts the value if it's different than the displayed text. So I expected displayField to be displayed, which it is, and valueField to be submitted, which is not.

The docs say that name defaults to '' and that it must be set if this field is to be automatically included with form.submit(), which it's clearly not as I have no name attribute and it's being submitted with the id attribute instead.

So next time I'll RTFM :">