Custom validating a NOT NULL column

It seems that if a column has ‘allow null’ unchecked, then Servoy always shows an ‘invalid input’ message as the user leaves the field. If I want to display my own message to the user I have to suppress the Servoy-generated message in an error handler.

I would like the ability intercept this condition myself in a table event, a column validation method, onDataChange and/or onFocusLost. Servoy should only generate its message after these methods have run, and only if/when I try to save the record.

Does this seem reasonable? Am I missing something?

Use a global error handling method on your solution. Under File → Solution Settings → on error method. Then in that global method, you can use the ServoyException node. It will throw a ServoyException.INVALID_INPUT error.

Keep in mind this is a solution wide change. So all errors in your solution will get passed into this method. If you do a move sample on the methods in the Servoy Exception node, you’ll get a nice bit of sample code to get you started.

Thanks for the reply Scott.

Yes I’ve used the error handler in that way before. There I can easily suppress all ‘invalid input’ error messages, but it would be nice if I could get Servoy-generated invalid input messages except on those columns where I’ve implemented my own error handling. This would provide me with much more flexibility.

Do you think I should log a feature request or is there some reason this just isn’t possible?

Hi,

i use the following construction to show my own error messages :
(by setting a global variable that contains the custom message)

The following code is part of the global error method.

if (e.getErrorCode() == ServoyException.INVALID_INPUT)
  {	
   application.beep()
   if (globals.validate_message == '--')
   {
     var thePressedButton = plugins.dialogs.showErrorDialog('Invalid Value', 'Ongeldige waarde of leeg veld !','OK');
     globals.validate_message = '--'
   }
   else
   {
     var thePressedButton = plugins.dialogs.showErrorDialog('Invalid Value', globals.validate_message,'OK');
     globals.validate_message = '--'
   }

Regards,

Hans Nieuwenhuis

Adrian,

Is is that you have implemented a global method validator for a column which also has a non-null constraint in the database? Or have you removed the constraint in favor of the validator?

Also, (And you probably already know this) your validation method must return true. Otherwise you’ll throw an INVALID INPUT error.

Replying to Hans:

Nice approach. I’m guessing you set the custom message variable in the onFocusGained event?

sdevlin:
Adrian,

Is is that you have implemented a global method validator for a column which also has a non-null constraint in the database? Or have you removed the constraint in favor of the validator?

Also, (And you probably already know this) your validation method must return true. Otherwise you’ll throw an INVALID INPUT error.

I am trying to implement a global validator for a column which also has a non-null constraint in the database. If I leave the field blank, I get Servoy’s invalid input message as soon as I tab out of the field, and my validator doesn’t even run.

Then it sounds like expected behavior.

Maybe try removing the non-null constraint (if that’s acceptable) and putting the check null into your validator (AFTER the other stuff you want to do first)

hope this is some help.

That’s what I have ended up doing. I have that luxury in this case because Servoy is the only app currently hitting my db, but if it were sharing the db with other apps that rely on the not-null property of the column (which it may do in the future) this workaround wouldn’t be available to me.

Then it sounds like expected behavior.

In my case, expected != desired