On Validate Event

I call a validating function on the Events “On Validate” of a field in my form.
image

It is said “Any invalid data will cause Five to show a message and force the user back to the field”.
In my case, after the error message, the user is not back to the field but allowed to go to the next field. The user can even save the record with an invalid input.
Here is the five.createError utilization in my code

See the following animated gift
existing-invoice

Did I made something wrong?

Thank you!

Hello,

I will need to take a look at the documentation and verify the functionality it describes, however, I have created an FDF to show you how to do this.

There is two options;

  1. If you would like the field to show the error and then reset to its original value:

You can set a variable in the ‘OnEdit’ event on the form in which sets a variable containing the original value of the field. If the field is then edited and an invalid value is entered, you can then set the field to the value of the previously set variable (the original, valid value it held), and then use five.showError(“message”). (function in FDF I supplied: ‘SetOriginalAge’ and ‘AgeValidate’)

  1. If you would like the field to keep the invalid value but not allow the user to save the form

You can add a function to the ‘OnComplete’ event of the form in which checks the value of the field, if it is invalid, return an error and the form will not save and will also stay in edit mode. (function in FDF I supplied: ‘FormValidate’)

In my FDF (attached below), an age greater than 10 is considered invalid.
ForumTesting-20250116-223957091485221.fdf (3.4 MB)

Let me know how you go!
Thanks,
Riley.

Thank you for the FDF provided, very appreciated.

I realized that “On Validate” works fine. I made a small sample with the event OnValidate and the behavior is as follow:

  • An error message pops up on exit when the value is not valid.
  • The label on the invalid field is red.
  • The whole record cannot be saved as long as the field is invalid.

For my current application

  • An error message pops up on exit when the value is not valid.
  • The label on the invalid field remains black, not red.
  • The record can be saved even if the field is invalid.

I think the problem was that five.createError() is called on the server side. I tried to call it on UI side but I cannot make it work, probably because the call is async.
Here is my function

The logs are all displayed, but there is no error dialog popping up. Is there a way to make this function works properly “On validate” ? or should I go the way like the FDF provided?

Hello,

Sorry I didn’t see that you were needing to do a query as well for the validation.

Here is a new template application (the same one but with a new function). I have detached the previous functions and created a new one called ‘DoBeforeInsert’. I have attached this function to the ‘Do Before Insert’ event on the User Table.

Logic: User enters an age, if this age is not already in the database, an error is returned and the user is unable to save the form.

Unfortunately, this still only occurs when the user clicks the confirm button on the form (they will not be able to properly save the form if the value is not within the database). If having this functionality occur within the On Validate event of a field is vital for your application, I can have a deeper look into finding a work around, just let me know!

ForumTesting-20250120-222644645177354.fdf (3.4 MB)

Thanks,
Riley.

Hello Riley,

Thanks for template application. The functionality occuring with the confirm button is good enough, it is not vital for me to link to the On Validate event of a field.

Now I have good receipes to validate almost all what I need :slight_smile:

Thank you!