PDA

View Full Version : Unable to access combobox store



Nagadev
13 Sep 2009, 9:54 AM
Hi , Please let me know whats wrong with following combobox code. I am unable to access its store in setValue() function (overridden function).
I could see the options list loaded when I Click on Selection, But unable to access its store when it is loaded initially. this.store returning undefined.



var comboPlans = new Ext.form.ComboBox({
name :'premPlanNo', id:'premPlanNo',lazyRender:true,typeAhead: true,
triggerAction: 'all', mode:'remote', allowBlank:false,
hiddenName:'premPlanNoId',
store: new Ext.data.JsonStore({
id:'plansStore',
root:'plans',
fields: [
{name:'value', mapping:'value'},
{name:'meaning', mapping:'meaning'}
],
url :contextPath + "/reportGenerator?"+operation+"=getPremiumPlans"

}),

valueField: 'value', displayField: 'meaning', fieldLabel :'Premium Plan', anchor :'95%'
});

saJoshua
13 Sep 2009, 9:59 AM
I can't see your usage of "this.store", but I can advise you to be careful with the "this" keyword unless you know exactly what you're doing with it. This is because "this" refers to the parent context of wherever you're using it.

Try using : comboPlans.store instead.

Nagadev
13 Sep 2009, 10:10 AM
Thanks for quick response. Here is the overridden setValue() function that i am using for combobox. this.store which is marked in below code is causing undefined exception



Ext.override(Ext.form.ComboBox, {
setValue: function(v){

if(this.mode == 'remote' && !Ext.isDefined(this.store.totalLength)){
this.store.on('load', function(){
var rec = this.findRecord(this.valueField, v);
this.setValue(rec ? rec.get(this.valueField) : '');
}, this, { single: true});
//if(this.store.lastOptions === null){
this.store.load();
//}
return;
}
var text = v;

if(this.valueField){
var r = this.findRecord(this.valueField, v);
if(r){
text = r.data[this.displayField];
}else if(this.valueNotFoundText !== undefined){
text = this.valueNotFoundText;
}
}
this.lastSelectionText = text;
if(this.hiddenField){
this.hiddenField.value = v;
}
Ext.form.ComboBox.superclass.setValue.call(this, text);
this.value = v;
}
});

saJoshua
13 Sep 2009, 12:38 PM
ok, try check if there is a store?



Ext.override(Ext.form.ComboBox, {
setValue: function(v){

if(this.mode == 'remote' && this.store && !Ext.isDefined(this.store.totalLength)){
this.store.on('load', function(){
var rec = this.findRecord(this.valueField, v);
this.setValue(rec ? rec.get(this.valueField) : '');
}, this, { single: true});
//if(this.store.lastOptions === null){
this.store.load();
//}
return;
}
var text = v;
.. etc...



May I ask what you're overriding the combo's setValue for?

Nagadev
13 Sep 2009, 10:33 PM
Thanks man,

My code works without any further changes, I am not sure why. I just configured two more comboboxes with similar requirement and tried executing and it simply works. some thing strange..

By the way to answer your question.. I have a grid on left hand side and trying to update the right hand side Form when I select a row in the grid. Where as when I load values from grid to form, the combo box is only setting value instead of displayValue from the list. Iam overriding the combobox setValue() to set the Display Value from the list based on the value.

Thanks.
Nagadev