PDA

View Full Version : which is the best way to update a combo textbox relaying on store changes?



callipigia
4 Aug 2010, 8:16 AM
I'm just trying to figure out how to reflect store updates to textbox area of a bounded combo.
More exactly, when it deletes or modify records in a store the text displayed in the combo box is not updated accordingly with the selected value (if any). However the text of list elements in the combo is updated correctly.

So far I worked out this piece of code which, to be honest, seems quite brute (c is the combo):



if (c && c.getValue()) {
var r = c.store.getById(c.getValue());
c.clearValue();
if (r) {
c.setValue(r.get(c.initialConfig.valueField));
}
}
and it doesn't work on modified records unless it uses Ext.getCmp('store_name') instead of c.store (it just deselect the current value)....

thanks

Condor
5 Aug 2010, 12:04 AM
and it doesn't work on modified records unless it uses Ext.getCmp('store_name') instead of c.store (it just deselect the current value)

Ext.getCmp('store_name') shouldn't return anything. A store isn't a component!

Is it only the displayValue that can change in the store or also the valueField?

callipigia
5 Aug 2010, 2:30 AM
only the display value can change
when it adds a new record it's not selected in the combobox so it's not required to update the combo textbox; however when it deletes a record which is selected, the combo should empty the textbox field

Condor
5 Aug 2010, 2:44 AM
Not only that, it should do a clearValue(), e.g.

store.on('remove', function(rec){
if (combo.getValue() == rec.get(combo.valueField || combo.displayField)) {
combo.clearValue();
}
});

callipigia
5 Aug 2010, 5:02 AM
yeah that works
but I've the problem to update the textbox when changes are made to the underlying record (display field)....I'm probably missing a combo.updateText() method or something to have the combo reloading its data....this is what I've tried



var c = Ext.getCmp('gecalPdlFiltroCombo');
if (c && c.getValue()) {
var r = gecalPdlFiltroStore.getById(c.getValue());
c.clearValue();
if (r) {
c.selectByValue(r.get(c.initialConfig.valueField));
}
}


That piece of code clears the combo when the record no longer exists and should reselect it if it exists and possibly has changed...the problem is that combo doesn't update the textbox (it doesn't reselect the value)

Condor
5 Aug 2010, 5:12 AM
No, you want setRawValue instead of selectByValue, e.g.

store.on('update', function(rec){
if (combo.getValue() == rec.get(combo.valueField)) {
combo.setRawValue(rec.get(combo.displayField));
}
});