PDA

View Full Version : [2.0a1][REOPENED] form.getValues() returns text instead of val of ComboBox



72
30 Sep 2007, 6:30 PM
Hi there,
subject is in title. When i am do the formAction.submit() and want to add extra parameters (fetch values from other form by getValues()) in place of ComboBox values are texts instead of vals. Checked in Firebug.
When i try to get it from just one ComboBox by getValue() it is ok.

Yes, i got right code, and i got set valueField.

I hope this is not a behavior!

Heres part of combobox initialization:

new Ext.form.ComboBox({
fieldLabel:'Algorithm',
store:new Ext.data.SimpleStore({
fields:['id','type'],
data:[
['AES','AES (Recomended)'],
['RC4','RC4']
]
}),
id:'AuthenticationAlgorithm',
name:'AuthenticationAlgorithm',
displayField:'type',
valueField:'id',
mode:'local',
typeAhead:true,
allowBlank:false,
forceSelection:true,
triggerAction:'all',
emptyText:'Select encryption algorithm',
selectOnFocus:true,
value:'AES'
})

72
30 Sep 2007, 6:59 PM
Oooh, i just inspected Ext source and it looks to be not so easy to fix it. All values are parsed from DOM and i have no idea if i can call item.getValue from Ext base adapter (originally it is serializeForm function of Ext base adapter)...

I am lil bit confused :-?

EDIT: Of course there is a problem with Ext ComboBoxes .. this is actually <INPUT TYPE="TEXT"> so it cant be done, i have to write my own serialize function...

EDIT2: So there is workaround needed.. use it if you faced same problem...


Ext.form.BasicForm.prototype.getRealValues = function(asString) {
var form = this;
if(typeof form != 'object') {
return null;
}

var el, name, val, disabled, data = '', hasSubmit = false;
for (var i = 0; i < form.items.length; i++) {
el = form.items.items[i];
disabled = el.disabled;
name = el.name;
val = el.getValue();

if (!disabled && name){
data += encodeURIComponent(name) + '=' + encodeURIComponent(val) + '&';
}
}
data = data.substr(0, data.length - 1);

if(asString === true){
return data;
}
return Ext.urlDecode(data);
}

jack.slocum
30 Sep 2007, 7:45 PM
If you want it to submit a value other than what is in the field, you need to trigger it to use a hidden field for the "value". The easiest way is to set the hiddenName config and it will work as you desire.

72
30 Sep 2007, 8:41 PM
Hey Jack :) thank You very much!

I am still learning, but first searching ... your way is pretty smart :)

christocracy
19 Oct 2007, 12:45 AM
when I provide a Combo with a default value and *do not* make any selection with it, getValue will return the displayField text, rather than the value.

I'm aware of hiddenName.



var combo = new Ext.form.ComboBox({
name: 'accounting_billing_method',
hiddenName: 'accounting[billing_method_id]',
tabIndex: 1,
width: 100,
listWidth: 100,
fieldLabel: 'Billing method',
allowBlank: false,
forceSelection: true,
triggerAction: 'all',
displayField: 'name',
valueField: 'value',
value: 'foo',
mode: 'local',
store: new Ext.data.SimpleStore({
'id': 0,
fields: ['value', 'name'],
data: [[1,'foo'], [2,'bar']]//Apollo.order.Util.getBillingMethods()
})
});
console.log('value: ', combo.getValue()); // <--- returns 'foo' rather than 1



is it a bug?

esoteric
22 Oct 2007, 8:32 PM
I am having the exact same problem, not matter how I select the data, on Ext1.1 and Ext2, please help.