OnDataChange method

Questions, tips and tricks and techniques for scripting in Servoy

OnDataChange method

Postby jcompagner » Wed Apr 05, 2006 10:42 pm

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("<html><body><font color='#ff0000'>Invalid value</font></body></html>");
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 Compagner
Servoy
User avatar
jcompagner
 
Posts: 8904
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby IT2Be » Sat Apr 22, 2006 12:41 pm

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...
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Postby LOGIsoft » Mon Mar 26, 2007 3:45 pm

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
Benoit R. Savignac, president
LOGIsoft Consulting inc.
--------------------------------------------------------
Servoy Alliance Network Partner
User avatar
LOGIsoft
 
Posts: 260
Joined: Wed May 24, 2006 3:06 pm
Location: St-Basile-le-Grand (Montreal), Qc, Canada

Postby jcompagner » Tue Mar 27, 2007 10:24 am

Ben,

do you return false when the validation fails? That should keep the user from switching to something else in 3.1.x
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8904
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby LOGIsoft » Tue Mar 27, 2007 12:58 pm

Hi Johann,

Here is the code I am using:

Code: Select all
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
Benoit R. Savignac, president
LOGIsoft Consulting inc.
--------------------------------------------------------
Servoy Alliance Network Partner
User avatar
LOGIsoft
 
Posts: 260
Joined: Wed May 24, 2006 3:06 pm
Location: St-Basile-le-Grand (Montreal), Qc, Canada

Postby jcompagner » Tue Mar 27, 2007 4:16 pm

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.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8904
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby LOGIsoft » Wed Mar 28, 2007 1:32 pm

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
Benoit R. Savignac, president
LOGIsoft Consulting inc.
--------------------------------------------------------
Servoy Alliance Network Partner
User avatar
LOGIsoft
 
Posts: 260
Joined: Wed May 24, 2006 3:06 pm
Location: St-Basile-le-Grand (Montreal), Qc, Canada

Postby jcompagner » Tue Apr 03, 2007 10:16 am

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?)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8904
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby chgog » Wed Apr 04, 2007 11:14 am

Thanks for this new feature :wink:
GOGUILLON Fabien
SOPADEV
SAN Developer
chgog
 
Posts: 130
Joined: Wed Dec 21, 2005 3:02 pm
Location: France / Anzin

Postby LOGIsoft » Wed Apr 04, 2007 12:49 pm

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
Benoit R. Savignac, president
LOGIsoft Consulting inc.
--------------------------------------------------------
Servoy Alliance Network Partner
User avatar
LOGIsoft
 
Posts: 260
Joined: Wed May 24, 2006 3:06 pm
Location: St-Basile-le-Grand (Montreal), Qc, Canada


Return to Methods

Who is online

Users browsing this forum: No registered users and 2 guests