PDA

View Full Version : Force Combobox value if...



fruitwerks
12 Sep 2009, 4:52 PM
I should have asked this in my last thread! but I marked it as solved so here is a new one...

I am to the point where my listener determines if the value if 'legal' (not validation) if the last selection was not legal - in my case, out of stock, I need to force it to my Out of Stock value. You are probably thinking why would these values be in the combo to begin with? Well, as we shuffle around items, they may become available or out of stock.

So my question is if my criteria matches and I need to force the value back to out of stock, what would need to happen?

Thanks!

saJoshua
13 Sep 2009, 9:34 AM
Hi Fruitwerks,

I'm guessing that you just want to "revert" the value of your combobox if something happens, right?

If this is the case, consider storing the "oldValue" on your combobox component, before the selection changes.



yourCombo.on('beforeselect', function(combo, record, index){
combo.oldValue = combo.lastSelectionText;
if(!combo.valueField || !combo.displayField || !record.data[combo.valueField || combo.displayField]){
return;
};
combo.newValue = record.get(combo.valueField || combo.displayField);
}, this);


With that in place, you can at any time after the selection has changed, revert it with a simple:


yourCombo.setValue(yourCombo.oldValue);

fruitwerks
13 Sep 2009, 12:57 PM
With that in place, you can at any time after the selection has changed, revert it with a simple:


yourCombo.setValue(yourCombo.oldValue);


Is exactly what I was looking for. I was surprised someone actually understood what I needed and bothered to help me out! In the meantime I put in place a message box telling us the selected item was out of stock - now I can replace that with your example and focus back on the combo... neato

I will let you know how it works out.

Thanks!