3.2.0

How to cancel value-changing on AW.UI.CheckBox.onControlValueChanging?

I am using an AW.UI.CheckBox. When I uncheck the control, I need to cancel this changing if some conditions satisfied. I tried as following:

CkCtl=new AW.UI.CheckBox;
CkCtl.onControlValueChanging = function(event){
var chk=this.getControlValue();
if(chk==true)
alert("Don't change!");
return false;
};

It doesn't work. The checkBox still changed value after this event.

How can I block/cance the value changing?

Thanks,
mrhsh
December 12,
CkCtl.onControlValueChanged = function(event){
var chk=this.getControlValue();
if(chk==false){
alert("Don't change!");
return this.setControlValue(true);
}
};
Carlos
December 12,
Thank you for your reply! As my understand, instead of "Cancel" value changing, your way lets the value chang anyway, and if the condition is satisfied, lets the value change back. It is a solution. However, I still wonder when/why we need onControlValueChanging event handler. Could you give me an example?

Thanks again!
mrhsh
December 14,
mrhsh, well , in some cases ther's a "way out" , but this is a case of :

When using (timing-event-handlers) like onControlValueChanging the changes in the "main reason/condition" of a function produces an endless-loop.

You can use a variable (switch it's valuel in the last line) and include it into the "if" statement to avoid that condition-loop or... save the whole function to a gloval variable ( then "cancel the changing function" , then value change) to finally restore the original.
Like I did in:
http://www.activewidgets.com/javascript.forum.15459.13/multi-row-marker-autoscrolls-to.html
where used a mix of both solutions (but not the "return" trick).

Sample:
CkCtl.onControlValueChanging = function(event){

var chk=this.getControlValue();
if(chk==false){
alert("Don't change!");

CkCtl.onControlValueChanging = function(event){ }
this.setControlValue(false);
}
return CkCtl.onControlValueChanging = runtime_onCVChanging;
}

var runtime_onCVChanging = CkCtl.onControlValueChanging;

Hope this helps
Carlos
December 15,

This topic is archived.

See also:


Back to support forum