PDA

View Full Version : [SOLVED] How to get the Text value from a ComboBox



vinnybozz
20 May 2009, 6:49 AM
I have a combobox where I want to allow the user to select an item from the dropdown list, or enter in directly a new value.

I created a quick example (no store) here:
http://jsbin.com/elala

If you SUBMIT with no inputs you will see a Quicktip telling you that the field is required.
However, if you enter any text into the combobox, it will pass the validation, but will the fields value will be "".

the source code can be edited at:
http://jsbin.com/elala/edit

thx for the help


Ext.onReady(function(){

var combo = new Ext.form.ComboBox({
allowBlank: false,
forceSelection: false,
anchor:'95%',
typeAhead: false,
mode: 'local',
fieldLabel: 'Value',
displayField:'value',
valueField: 'value',
hiddenName: 'value',
name: 'value',
required: true
})

var p = new Ext.FormPanel({
title: 'My Panel',
collapsible:true,
renderTo: 'container',
width:400,
height: 200,
items: [combo],
buttons: [{
text: 'submit',
scope: this,
handler: function() {
if(p.getForm().isValid()) {
vals = p.getForm().getValues();
alert("Combo box value: " + vals.value);
console.debug(vals);
}
}
}]
});
})

chinnapandu
20 May 2009, 9:22 PM
Hi,

Try doing this add id: 'MyComboBox' to the combo box instance. In form panel submit button handler function write this code

if(p.getForm().isValid()) {

var form = p.getForm();

var myComboBox = form.getComponent('MyComboBox');

alert("Combo box value: " + myComboBox.getValue());



}

Animal
20 May 2009, 11:30 PM
If there are not seperate value and text fields, then you don't need a hiddenName do you? Think about it.

You will be submitting a multi-values input. Both holding the same value!

vinnybozz
21 May 2009, 4:49 AM
thx Animal that makes sense.

changing my hiddenName field to name effectively solved this.