PDA

View Full Version : Help for people struggling with ComboBox values



DrZog
26 Apr 2007, 6:03 AM
If you've converted your old school ComboBox into a slick Ext one and are wondering why the parameter posted is the selected value and not the option value, remember to set these two options in the ComboBox definition:


valueField: This is what you want your value set to (from your datastore)
hiddenName: This is an autocreated hidden field that gets the value of what ever you select

e.g.


var comb = new Ext.form.ComboBox({
store: myStoreDs,
displayField:'Name',
valueField: 'id_users',
hiddenName: 'idOfUsers',
typeAhead: true,
triggerAction: 'all',
emptyText:'Select a name...',
selectOnFocus:true
});

and voila, no more hairloss

benny
26 Apr 2007, 6:16 AM
Was just struggling with this now.... but still no luck..

I just get empty spaces where the options should be, this is my generated code:

<div>
<input type="text" id="cat-list_1" size="20"/>

</div>
<script>
// simple array store
var store_1 = new Ext.data.SimpleStore({
fields: ['id', 'item'],
data : [{"id":"2","item":"Reportable"},{"id":"3","item":"Non-reportable"}]});
var combo_1 = new Ext.form.ComboBox({
store: store_1,
displayField:'item',
valueField:'item',
hiddenName:'id',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
emptyText:'Select an item.....',
selectOnFocus:true
});
combo_1.applyTo('cat-list_1');
</script>

..any ideas?

DrZog
26 Apr 2007, 6:33 AM
Benny, try putting your code into the format that Brian has suggested in his intro article:

i.e.


Ext.onReady( function(){

//Put your code here

});

gives the dom time to initialise

benny
26 Apr 2007, 7:00 AM
thanks drZog, but it didn't fix my problem. I think it has something to do with the data source - I probably need to run the Json through the JsonReader somehow.

benny
26 Apr 2007, 7:28 AM
OK, got it to work. The Json data had to be put through the JsonReader... like this:


var store = new Ext.data.Store({
reader : new Ext.data.JsonReader({},['id', 'item'])
});
store_.loadData(<?=$raw_json_data?>);

DrZog
26 Apr 2007, 10:45 PM
Kewl B)