View Full Version : Combobox - select value

8 Feb 2012, 8:35 AM
I have to set a specific value to a combobox but the value is shown in the field instead of the displayField.
Here are my store and my combo :

var mystore = new Ext.data.JsonStore(
baseParams : {start: 0, limit:6},
autoLoad : false,
url : 'myurl.php',
root : 'data',
totalProperty : 'total',
idProperty : 'num',
fields : [
{name: 'num', type: 'string', mapping: 'num'},
{name: 'title', type: 'string', mapping: 'title'}
var mycombo = new Ext.form.ComboBox({
fieldLabel : 'My Combo',
name : 'mycombo',
id : 'mycombo',
hiddenName : 'mycombo',
typeAhead : true,
store : mystore,
valueField : 'num',
displayField : 'title',
mode : 'remote',
triggerAction : 'all',
itemSelector : 'div.search-item',
validationEvent : false,
forceSelection : true,
enableKeyEvents : true,
lazyInit : false,
width : 170,
listWidth : 400,
pageSize : 6,
minChars : 0,
tpl : '<tpl for="."><div class="search-item"><div class="Num">{num}</div><div class="CLS">{title}</div></div></tpl>'

It's a combo with a template and a pagination. I think the issue is because of that.
I tried to set the property "value" of the combo, I tried the methods "setValue" and "selectByValue" but it always shows the value in the field and not the displayField.
When I expand the combo, I see that the right value is selected, but I would like that my title is shown in the field and that the right lign is selected when I expand the combo. Because if I put the title as the value, the right lign is not selected when I expand the combo.
I hope my explainations were clear and that somebody will have any idea !

8 Feb 2012, 8:52 AM
This is because the store isn't loaded so it doesn't have a displayValue. You need to set a listener for when the store is loaded and use setValue

9 Feb 2012, 12:11 AM
Yeah it works !
Thanks a lot !