-
14 May 2007 7:07 PM #1
Set ComboBox selected value from form.load()
Set ComboBox selected value from form.load()
I've got a form inside a LayoutDialog. This form loads its data dynamically when a row in a grid is double clicked. Most of it works great, but one field, a ComboBox, does not select its appropriate value automatically.
The ComboBox also loads its values dynamically via JSON. What do I need to do to select the appropriate value in the ComboBox when the form loads data?
Code:var companies = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url: 'companies.php?Action=Get' }), reader: new Ext.data.JsonReader({ root: 'companies' },['company_id', 'company_name']) }); companies.load(); var cmpCombo = new Ext.form.ComboBox({ fieldLabel: 'Company', store: companies, displayField: 'company_name', typeAhead: true, valueField: 'company_id', emptyText: 'Select company...' }); var frm = new Ext.form.Form({ labelAlign: 'left', labelWidth: 125, waitMsgTarget: 'project-info', reader: new Ext.data.JsonReader({ root: 'project', totalProperty: 'totalCount' }, [ {name: 'project_name', mapping: 'project_name', type: 'string'}, {name: 'project_description', mapping: 'project_description', type: 'string'}, {name: 'company_id', mapping: 'company_id', type: 'string'} ]) }); frm.fieldset( {legend:'Project Information'}, new Ext.form.TextField({ fieldLabel: 'Project Name', name: 'project_name', width:190 }), new Ext.form.TextArea({ fieldLabel: 'Description', name: 'project_description', width: 400, height: 150 }), cmpCombo ); frm.render('project-info-form'); cmpCombo.render(); return frm;
-
15 May 2007 3:30 AM #2
Have you tried combo.setValue(...) method?
Jozef Sakalos, aka Saki
A lot of valuable info at:
Saki's Extensions and Plugins
Saki's Extensions and Plugins Docs
Saki's Examples, Latest: Grid in Card Layout
Saki's Blog, Featured: Writing a Big Application in Ext, Latest: Grid MultiSearch Plugin Video
-
15 May 2007 5:22 AM #3
Figured it out...I didn't specify the right name for the combo box in its config section. I set that properly and it works now. What I get for coding at 11:30 at night...
-
19 May 2009 6:17 AM #4
I have the same problem
I have the same problem
rswafford:
I have the same problem and I see in the post that you have the solution but I did not understand it at all. Could you please put the complete code here. Thanks
-
11 Apr 2011 6:38 AM #5
Complete code could be great
Complete code could be great
Hi, thx for your help about combobox loading data,
but I'm in the same case, and the complete code could be helpfull
in addition to your short explains.
now, no matter
-
15 Nov 2011 4:51 AM #6
http://docs.sencha.com/ext-js/4-0/#!...ethod-setValue
This works fine for me.
The "Name" and "url" are my textfields names. the country is the combo box name. Please note that in order to display a new value in the combo box you must send a value that exists in the combo box and only then it will be able to show the responded value.Code:EditPartnerProfileForm.getForm().setValues({ Name : strtojson.displayname, url : strtojson.url, country : strtojson.country });
setValue( String/String[] value ) : Ext.form.field.FieldSets the specified value(s) into the field. For each value, if a record is found in the store that matches based on the valueField, then that record's displayField will be displayed in the field. If no match is found, and the valueNotFoundText config option is defined, then that will be displayed as the default field text. Otherwise a blank value will be shown, although the value will still be set.


Reply With Quote