PDA

View Full Version : [Solved] Default Combo Box Value with getAt(0)



danaxelrod
16 Jan 2011, 9:12 PM
Tying to set a default value below in bold, displaynames is my store. This is probably not the right method of doing this.
I am getting the correct value as it's displayed by the alert at the bottom.
Also, do I need to get and set the default valueField to displaynames.getAt(0).get('id'), and how is this accomplished?
Thanks!


xtype: 'combo',
id: 'nameBox',
name: 'displayname',
fieldLabel: 'Name',
mode: 'local',
selectOnFocus: true,
value: displaynames.getAt(0).get('id'),
typeAhead: true,
editable: false,
triggerAction: 'all',
store: displaynames,
displayField:'displayname',
emptyText: '-Select-',
valueField: 'id',
width: 130,
listeners: { select: {fn: function(){
updateTxDates(this.value)
alert (displaynames.getAt(0).get('displayname'))
}
}
}

Condor
17 Jan 2011, 8:09 AM
Is the displaynames store already loaded when you do this?

danaxelrod
17 Jan 2011, 8:15 AM
Thanks for your reply. I believe so. I get the same problem even when I see the names populated in the combo box.

Condor
17 Jan 2011, 8:23 AM
If your store were already loaded then you wouldn't have a problem. Try if this override (http://www.sencha.com/forum/showthread.php?75751-OPEN-42-ComboBox-s-setValue-call-with-a-remotely-loaded-Store&p=400274#post400274) helps.

danaxelrod
17 Jan 2011, 10:06 AM
Actually, you're right, the value is undefined when the combo box tries to access it. I tried the override without success. I just put at the top of my code in the Ext.onReady function. Do I have to modify the override code?

danaxelrod
17 Jan 2011, 5:41 PM
Is there a way to delay the combobox execution until after the store is loaded?

vishalnnsingh
17 Jan 2011, 10:57 PM
use the forms render event

danaxelrod
17 Jan 2011, 11:07 PM
I think this is what you mean, but it doesn't work.

var patient_form = new Ext.FormPanel({
url: 'movie-form-submit.php',
renderTo: document.body,
frame: true,
title: 'Patent Search Form',
render: function() {
Ext.getCmp('nameBox').setValue(displaynames.getAt(0).get('displayname'))
},
width: 450,

Condor
17 Jan 2011, 11:40 PM
No, don't use the render event. You have to use the store load event, because that's the only time you can be sure the store contains data.

danaxelrod
18 Jan 2011, 7:32 AM
Thanks everyone! Condor's suggestion works nicely:


displaynames.load({
params: {status: 'Active'},
callback: function(){
Ext.getCmp('nameBox').setValue(displaynames.getAt(0).get('displayname'));
}
});