Our hackerforms lib provides a full variety of pre-validated widgets, from mighty read_file and display_iframe to life-saving handymen such as read_pandas_row_selection (and we add new ones every week). These are amazing to quickly add to your Smart Form and get moving.
But we know customization is key, so it's just as easy to adapt these with your own validation methods in Abstra Cloud. This is what we call the validate feature, which can be added to your Pages.
You just create a validate function with your own business rules that returns a boolean and an error message and pass it in the Page's run method. Let's see how to do that with a couple of examples.
Today we'd like to create a form that can only be answered by people over 18, and that has to be made clear. In our function we'll make sure no one can enter an empty value and we'll create the True condition: inputting the number 18 or higher. We'll also add the error message to help the Form's user make sense of any mistakes.
Then just create the Page with your read widget (we're going to take advantage of read_number's included type validation) and add validate in the Page's run method:
We could also do this dynamically using the read_date widget and datetime lib.
We just have to import datetime and add the age logic inside the function: get today's date, subtract it from the informed birthday and check if that's over 18. If it is, the user can get through. The rest stays the same:
Use the validate function within your Smart Forms to build customized business logic, adaptable to any process - start right now.
Got a use case in mind? We'll help you build it in 15 minutes here.
See you next time!