PDA

View Full Version : How can I display combobox text after form load?



yumusakg
15 Mar 2012, 4:27 AM
I can post the value of remote combobox with hiddenName. I couldn't accomplish showing the text of combobox after form load. This is a remote combo. So the store is not loaded after form load. So the combo only shows the value field...

config for combobox


Ext.ns('portal', 'portal.common');

portal.common.store_combo_company = new Ext.data.JsonStore({
root: 'data',
url: '../common/presentation/commondata.aspx',
baseParams: {
cmd: 'combo_company'
},
fields: [{
name: 'ParamID',
type: 'int'
},
{
name: 'ParamDescription',
type: 'string'
}]
});

portal.common.ComboCompany = Ext.extend(Ext.form.ComboBox, {
constructor: function(config) {
config = Ext.apply({
store: portal.common.store_combo_company,
valueField: 'ParamID',
displayField: 'ParamDescription',
fieldLabel: 'Firma',
mode: 'remote',
typeAhead: false,
triggerAction: 'query',
minChars: 2
}, config);

portal.common.ComboCompany.superclass.constructor.call(this, config);
}
});

Ext.reg('combocompany', portal.common.ComboCompany);

apart from form's config


{
id: 'form_contract',
url: 'prcdata.aspx',
xtype: 'form',
baseCls: 'x-plain',
labelWidth: 120,
bodyStyle: 'padding:10px',
defaults: { anchor: '100%', xtype: 'textfield' },
items: [{
fieldLabel: 'contractId',
name: 'contractId',
xtype: 'hidden'
}, {
id: 'prc_firma',
xtype: 'combocompany',
emptyText: 'Sešiniz',
hiddenName: 'Firma'
}]
}

mitchellsimoens
15 Mar 2012, 10:35 AM
If the store hasn't finished loading when you set a value to the combo then you will need to reset the value once the store has finished loading.

yumusakg
15 Mar 2012, 10:35 PM
the combo retrieves 5000 rows. so i don't want to load these rows in form load... what i wanted to make is displaying combo value and text without loading combo store...

fschaeffer
16 Mar 2012, 1:15 AM
You could use setRawValue to simply display the value you want.

I usally use a combination of setValue & setRawValue. So the combobox IS aware of the to-be-used-value and correctly transmits the value but without loading the store...

HTH
Florian

yumusakg
16 Mar 2012, 1:43 AM
thank you @fschaeffer,

setRawValue worked very well.

But it is extra code to implement this common requirement.. I think this must be functionality of combo component. An additional config item like loadValue which will bind the action.result.data.<data_item> to combobox RawValue could be easily implemented.. so we didn't have to write extra code..