PDA

View Full Version : newbie question : set a value for the displayField for a combobox



flamant
29 Oct 2010, 4:27 AM
Hi,
it is possible to set a value for a combobox (coresponding to the valueField) but how can we set the text displayed in it (corresponding to the displayField) independently ?

plalx
29 Oct 2010, 5:28 AM
how can we set the text displayed in it (corresponding to the displayField) independently ?

Not sure to understand the question? What are you trying to do?

flamant
29 Oct 2010, 5:42 AM
for a combo, you have the value (that will be posted) and the text displayed. there is a method to set the value but not the text and I would like to set the text that will be displayed.

it is the same for javascript for a select element
<select ...>
<option value="code">Example</option>
.............
</select>

In Extjs you can set the value "code" but not the text "Example"

plalx
29 Oct 2010, 6:00 AM
If the valueField and displayField config options are properly set on the combobox, setting the value using combo.setValue(/*value of valueField*/) should show the associated displayField text in the combobox...

flamant
29 Oct 2010, 6:21 AM
yes but in my case, I haven't already a store for the combobox. I just want to initialize the combo with a value and a text

plalx
29 Oct 2010, 7:24 AM
Well, I think you need a store... You can instanciate a store passing in the values you want.



Ext.onReady(function() {
var cbo = new Ext.form.ComboBox({
renderTo: document.body,
mode: 'local',
displayField: 'text',
valueField: 'id',
value: 1,
store: new Ext.data.JsonStore({
fields: ['id', 'text'],
data: [
{id: 1, text: 'My Value'}
]
})
});
});

flamant
29 Oct 2010, 9:06 AM
Yes indeed I instanciate a store. Thank you for your answer