Changing value of a combo box Ext.form.ComboBox Ext JS
I am having a little trouble setting the value of a combo box within the code.
I have the following select box
new Ext.form.ComboBox({
id: 'address_type',
name: 'address_type',
editable: false,
disableKeyFilter: true,
forceSelection: true,
fieldLabel: 'Type',
emptyText: 'Please Select',
triggerAction: 'all',
mode: 'local',
store: new Ext.data.SimpleStore({
id: 0,
fields: ['value', 'text'],
data : [['Home', 'Home Address'], ['Work', 开发者_JS百科'Work Address']]
}),
valueField: 'value',
displayField: 'text',
hiddenName: 'address_type'
})
So surely if I executed:
Ext.getCmp('address_type').setValue('Work')
Would set the value of the select box to 'Work Address'? However it doesn't appear to work.
Any advice appreciated, thanks.
The problem may be that Ext.getCmp
call is failing because you have defined identical id
and hiddenName
for the ComboBox
.
ExtJS (now Sencha) API documentation states the following:
hiddenName : String
If specified, a hidden form field with this name is dynamically generated to store the field's data value. ...
Note: the hidden field's id will also default to this name if hiddenId is not specified. The ComboBox id and the hiddenId should be different, since no two DOM nodes should share the same id. So, if the ComboBox name and hiddenName are the same, you should specify a unique hiddenId.
So, you should try to give your Combobox
a unique hiddenId
and see if it works then.
精彩评论