OnDataChange method

onDataChange is changed a bit.
from now on (3.0b2) you get the oldValue and newValue as arguments
and if you return false. Servoy will set the focus back into the field. And then onDataChange
is also called again if the user didn’t change the value after so that again you can say “Still wrong value” and return false.

sample script:

var oldValue = arguments[0];
var newValue = arguments[1];
if(newValue == “1”)
{
application.setStatusText(“Invalid value”);
return false
}
application.setStatusText(“”);

In servoy it is now not possible to jump to anyother field (record/listview or tableview) if the onDataChange tells us that
the validation did go wrong.

Johan, this is great! Thanks for that…

I think this is a step into the direction of those asking for a keypressed event. It doesn’t replace that of course be in many cases that demand is not there anymore!

Thanks again…

Johann,

When using a portal on a form, I can still move to another field/portal row, even if my validation fails. Is there a way to prevent this, so that we can make sure that the user enters the correct information before leaving the field?

Really looking forward to column validation… :wink:

Using Servoy v3.1.3 build 407 with Sybase iAnywhere 9.

TIA,

Ben

Ben,

do you return false when the validation fails? That should keep the user from switching to something else in 3.1.x

Hi Johann,

Here is the code I am using:

var oldValue = arguments[0];
var newValue = arguments[1];

var msg = "You have not entered a valid time for this shift. \n Please re-enter the time correctly using any of the following formats: \n 1a-2p, 1am-2pm, 115am-215pm, 1:15am-2:15pm."

if( utils.stringPatternCount( newValue , "-" ) > "1") 
{
   plugins.dialogs.showWarningDialog( 'Error' ,  msg,  'OK')
   return false
}

For some reason, if I leave the field and there are more than one dash, the dialog pops up correctly, but the field value does not revert to the original one, even though the validation failed. Are there some specifics I should put in place so that the validation works?

Thanks in advance,

Ben

We don’t revert it to the previous value. If you want to do that then set the old value again in the dataprovider. and it will be reverted.
We can’t do that because that would be quite annoying if you ask me. If i type something completely different then what it was before and i make one small mistake and suddenly everything is reverted then i am not very pleased.

Maybe, but that would go a long way in helping to control valid data entry. At least if we had the option of strictly enforcing the validation or letting the user off with a warning (as it stands now), that would be very helpful.

Also, it does not explain why this part doesn’t work for me:

In servoy it is now not possible to jump to anyother field (record/listview or tableview) if the onDataChange tells us that
the validation did go wrong.

Is it because I’m using the validation method in a portal field? :?

TIA,

Ben

portal is kind of the same thing as a tableview. So when you return false in a ondatachange method you shouldn’t be able to leave the field.

Are you saying that you still can leave the field (and if you do the same in a tableview you can’t?)

Thanks for this new feature :wink:

I haven’t tried it in table biew, but the onDataChange method still allows me to get out of the portal field in question. Doesn’t matter for now though, as we’re sort of putting this issue on the sidelines for now… :wink:

Thanks again,

Ben