PDA

View Full Version : Using ComboBox to get Old Value?



shaoen01
3 Dec 2011, 7:11 PM
Hi all,

I am currently using a combo box or dropdown menu on my grid with roweditor plugin. I would like to know the old value before it was selected. I am using the change listener to do that. However, there are a few ways to select the value. Either you use a mouse click to select (in this case change will be fired) or you can type in and there's an autocomplete.

So in the auto-complete mode, say the actual value is "abc123" and i am typing "ab" it will show a potential match. So i normally just do a tab and the full value gets populated. So in this case, i am unable to get the old value. Could it be that change event is not fired? Any advise on how to handle non mouse-click selection?



field: {
xtype: 'combobox',
id: "namecombo",
typeAhead: true,
triggerAction: 'all',
selectOnTab: true,
store: userstorecombo,
displayField: 'fullname',
//valueField: 'productid',
lazyRender: true,
allowBlank:false,
listClass: 'x-combo-list-small',
msgTarget: 'side',
queryMode: 'local',
listeners: {
scope: this,
select: function(field, value, options)
{
selected_combo_display=field.getRawValue();

},
change: function (field, newValue, oldValue, options) {
selected_combo_display=newValue;
selected_combo_display_old=oldValue

}
}//end listener

}

skirtle
4 Dec 2011, 10:36 AM
Why do you need the old value? There are loads of ways to get hold of the old value but it's difficult to say what's best without knowing the use case. Until the edit completes the old value will be accessible through the record. The events beforeedit and validateedit both provide an opportunity to grab it.

The change event should fire no matter how the value was changed, though it may only fire when the field blurs. Add in some console logging to confirm. You need to be careful though, if the change event fires multiple times then your 'old value' will not be the original value, it will be the value from the previous change event.

shaoen01
4 Dec 2011, 3:29 PM
Thanks, i think i will have to find another way to do it.