PDA

View Full Version : Setting the "selected" combobox option



taelo
13 Dec 2010, 12:04 PM
I am populating a form with values from a database.

editSwitchForm.getForm().load({
url: 'get-switch-data.php?id=' + e.attributes.id,
method: 'GET',
waitMsg:'Loading...'
});
buildingCombo.store.load();

I am attaching a combobox to the same form,

var editSwitchForm = new Ext.FormPanel({
...
items : [ buildingCombo, editSwitchFormLayout ],
...

The editSwitchForm does not have a JsonStore associated with it, but the buildingCombo does.

With all that being said, I have some questions:
1) If the fields are properly mapped in the formPanel, should the combobox set its default selected option based on the response from editSwitchForm.getForm().load()?
2) If the formPanel will not auto set the selected option, how can I get the value from the returned data set (since the function does not store the values in a JsonStore)?

taelo
13 Dec 2010, 2:30 PM
I managed to get the combobox to select the option based on response from the database, however, the numeric ID I passed is being displayed as the option and not the displayField. Any ideas?

var buildingCombo = new Ext.form.ComboBox({
store : new Ext.data.JsonStore({
url : 'get-buildings.php',
root : 'data',
fields : [{name: 'building_id'}, {name: 'building_name'}]
}),
fieldLabel : 'Building',
displayField : 'building_name',
hiddenName : 'building_id',
typeAhead : true,
triggerAction : 'all',
mode : 'local',
width : 125,
minChars : 0,
emptyText : 'Select a Building'
});

taelo
13 Dec 2010, 3:10 PM
custom renderer is not working either :/

renderer : function(value) {
var idx = buildingCombo.store.find(buildingCombo.valueField, value);
var rec = buildingCombo.store.getAt(idx);
return rec.get(buildingCombo.displayField);
}

EDIT: It works now. I was not specifying a valueField...

Much thanks to nkohar -> http://www.sencha.com/forum/showthread.php?21379-ComboBox-renderer-for-EditorGridPanel&p=165242