PDA

View Full Version : Combobox: setValue happens before store is loaded?



hallikpapa
5 Aug 2009, 8:01 PM
My combo box has id & name. I make two separate calls to load the combo box & to get user data. The data that is returned is the id field, and I am trying to get it to display the correct name based on what id is returned. Right now it's displaying the id instead of the name. Stepping through the code, it LOOKS like it is trying to set the value before the store is completely loaded (findValue function, it does not pass this.store.getCount > 0). Where have I gone wrong?



// create namespace for plugins
Ext.namespace('Ext.ux.adportal');

Ext.ux.adportal.BilletCombo = function(config) {

// call parent constructor
Ext.ux.adportal.BilletCombo.superclass.constructor.call(this, config);

this.tpl = config.tpl ||
'<tpl for="."><div class="x-combo-list-item x-icon-combo-item {'
+ this.iconClsField
+ '}">{'
+ this.displayField
+ '}</div></tpl>'
;

this.on({
render:{scope:this, fn:function() {
var wrap = this.el.up('div.x-form-field-wrap');
this.wrap.applyStyles({position:'relative'});
this.el.addClass('x-icon-combo-input');
}}
});
}

Ext.extend(Ext.ux.adportal.BilletCombo, Ext.form.ComboBox, {

initComponent: function() {
Ext.apply(this, {
store: new Ext.data.Store({
reader : new Ext.data.JsonReader({
root : 'data'
}, [ {
name : 'id', type : 'int'
},{
name : 'name', type : 'string'
}]),
autoLoad : true,
url : '../extjs.php?act=billet'
}),
valueField : 'id',
displayField : 'name',
//hiddenName : 'id',
triggerAction: 'all'
//mode: 'remote'
});
Ext.ux.adportal.BilletCombo.superclass.initComponent.apply(this,arguments);
},
setValue: function(value) {
Ext.ux.adportal.BilletCombo.superclass.setValue.call(this, value);
}

});

//register xtype
Ext.reg('billetcombo', Ext.ux.adportal.BilletCombo);

Animal
5 Aug 2009, 9:23 PM
I have an FR out to fix this: http://extjs.com/forum/showthread.php?t=75751

Condor's code is the best solution.

hallikpapa
5 Aug 2009, 9:41 PM
Thank you for the suggestion, this works as far as displaying the data correctly, but it gets stuck in an endless loop of calling the extjs.php?act=billet. Ideas?



setValue: function(value) {
if(this.store.state != 'loaded'){
this.store.on('load', this.setValue.createDelegate(this, arguments), null, {single: true});
if(this.store.state != 'loading'){
this.store.load();
}
Ext.ux.adportal.BilletCombo.superclass.setValue.call(this, value);
return;
}

}

Animal
5 Aug 2009, 9:47 PM
You have the Store loading state change addition too then?

hallikpapa
5 Aug 2009, 9:51 PM
You have the Store loading state change addition too then?

Yes, looks like it? Let me read that thread again. I edited my post after your posted, but I am stuck in an endless loop. Perhaps what you mentioned is causing this.

removing this line did not fix my endless loop. so I will dig a bit deeper


//if(this.store.state != 'loading'){
// this.store.load();
// }

hallikpapa
5 Aug 2009, 9:59 PM
Oh I misunderstood. I thought the loading, loaded features were there. Not suggestions you were making. I am still stuck in my endless loop, fyi. So I will keep stepping through it



setValue: function(value) {
if(this.mode == 'remote' && !Ext.isDefined(this.store.totalLength)){
this.store.on('load', this.setValue.createDelegate(this, arguments), null, {single: true});
if(this.store.lastOptions === null){
this.store.load();
}

return;
}
Ext.ux.adportal.DistrictCombo.superclass.setValue.call(this, value);
}


<edit>
Sorry for my stupidity, very tired. The above works and is not an endless loop. Thanks

Animal
5 Aug 2009, 10:05 PM
Get some rest. There's a law of diminishing returns on long coding sessions!

rstuart
30 Apr 2010, 7:44 PM
Sorry to bring this up again, but I can't seem to get a solution to this issue. I have to combo boxes. Both use the same data (although different store objects) and I am trying to carry a value from the first combo over to the second combo. My problem is that I am using the combos in remote mode with a page size of 20.

To solve the problem, I tried to do the following things:


expand() the ComboBox (which just does nothing for some reason).
doQuery() on the ComboBox using the display field value of the first ComboBox to make sure the record was in the store.
call setValue() with the value from the first ComboBox.

After seeing this thread I also added the override mentioned in the [OPEN-42] thread. My problem is that expand() and doQuery() don't seem to be doing anything. I have tried removing the expand() and only using doQuery() and while I can see the request being sent to the server, nothing happens in the ui (someone in [OPEN-42] thread said the list should expand but it doesn't).

Is there a specific way to accomplish what I am trying to do? Code below (the code is for a window that has 4 filters horizontally across the top and a grid to display results below. I have tried to remove everything but the ComboBox in question).


CTiL.ui.DuplicatesViewer = Ext.extend(Ext.Window, {
Ext.apply(this, {
title: 'Find Duplicates',
modal: true,
width: 900,
height: 450,
bodyStyle:'background-color: transparent',
defaults: {
border: false,
bodyStyle:'background-color: transparent; padding:5px'
},
items: [new Ext.Panel({
bodyStyle: 'background-color: transparent; padding:5px 5px 0',
border: false,
items: [{
bodyStyle: 'background-color: transparent',
border: false,
items: [new Ext.Panel({
bodyStyle:'background-color: transparent',
border: false,
defaults: {
border: false,
bodyStyle:'background-color: transparent'
},
layout: 'column',
items: [{
layout: 'form',
columnWidth: .25,
items: [new Ext.form.ComboBox({
name: 'strategy',
id: 'dStrategy',
store: new Ext.data.JsonStore({
proxy: new Ext.data.HttpProxy({
url: '/interventions/strategies/',
method: 'GET'
}),
root: 'rows',
totalProperty: 'results',
fields: ['id', 'desc']
}),
loadingText: 'Fetching Strategies...',
typeAhead: false,
pageSize: 20,
hideLabel: true,
valueField: 'id',
displayField: 'desc',
listWidth: 300,
triggerAction: 'all',
minChars: 2,
emptyText: 'Select a Strategy...'
})]
}]
})]
})]
})]
});
CTiL.ui.DuplicatesViewer.superclass.initComponent.call(this, arguments);
this.on({
'show': function() {
// TODO: Can't get this to work, not sure exactly how to do it.
// Introduction of paging and the use of a remote store has complcated the issue...
// Set filters to inital values
if (Ext.getCmp('aStrat').getValue() !== '') {
//Ext.getCmp('dStrategy').expand();
Ext.getCmp('dStrategy').doQuery(Ext.getCmp('aStrat').getStore().getById(Ext.getCmp('aStrat').getValue()).get('desc'), true);
Ext.getCmp('dStrategy').setValue(Ext.getCmp('aStrat').getValue());
}
}
});
}
});

rstuart
1 May 2010, 6:20 PM
Problem solved. I had to modify my load code to the following:


this.on({
'show': function() {
// Set filters to inital values
if (Ext.getCmp('aStrat').getValue() !== '') {
Ext.getCmp('dStrategy').getStore().on({
'load': {
fn: function() {
Ext.getCmp('dStrategy').setValue(Ext.getCmp('aStrat').getValue());
},
single: true
}
});
Ext.getCmp('dStrategy').doQuery(Ext.getCmp('aStrat').getStore().getById(Ext.getCmp('aStrat').getValue()).get('desc'), true);
Ext.getCmp('dStrategy').setValue(Ext.getCmp('aStrat').getValue());
}
}
});Some notes:


I have to do a double setValue() because part of loading the window relies on getting any existing filter values so I can load the main grid.
The documentation for doQuery() does not mention that it will also try to expand the list.
The documentation for expand() doesn't say that it will only expand if the ComboBox has focus.
I had to remove the override suggested in [OPEN-42]. It would fail silently when I first called it. I didn't investigate why, I just removed it and it worked.

I hope someone finds this useful.

varunach
22 Apr 2011, 11:59 AM
In case you are using triggerAction : 'all', the simplest solution is this:

Change the combo's mode to 'local', set the store's autoLoad to false and do this :



listeners : { afterrender : {
fn : function(combo){
combo.getStore().load();
combo.getStore().on('load', function(){
combo.setValue(combo.getStore().getById(1).get('xyz'));
});
}
}
}
}

This works perfectly for me (atleast currrently), since the combo is set to local it only loads once, hence using the load listener works only once..
I'm sure something similar can be worked out for triggerAction : 'query'.. I don't have the time to try it out right now.. but if i ever get an requirement, i'll try it out and post it hear...

@Animal : see any thing wrong with this approach that might come bite me in the butt later? :-?

karthik27061973
10 Jul 2016, 2:58 AM
Hi,

The above link does not seem to exist.
Where could I get the solution?

Regards.

karthik27061973
10 Jul 2016, 3:00 AM
The message I get is that I do not have permission to access the page.
How do I proceed?