I have a form where the user enters some field data. When the user clicks the button to “submit” a function is called that checks for errors/validations and if errors sets page states etc. so user can see where/why the errors were, and fix them. STOP. If there are no errors after checked by the function, the field data is added to the database as a new entity, then the user should be navigated to the next Page. How can we do that with functions? : Check for errors, if errors, display them on the page so user can try again-STOP, else, save data to database and navigate to next page.
Hi,
To display errors, you can use States (conditional states bound to a datasource returned by your function in case of errors).
You can also enable / disable states from the back end with enableState() and disableState() if there are errors.
For the navigation, you can use a Page loader bound to a shared datasource.
Your function can return in this shared datasource the page to navigate on if there are no errors.
The states of the Page are working well for catching and displaying the errors. Is there any way to just navigate to another page if all is successful, without using the page loader? ie some code in the function that says: if all good navigate to Page abc123? Or is Page loader necessary/strongly preferable for this kind of thing? Thanks.
Hi Musseman, we appreciate your input.
In your case, a page loader must be used and bound to a variable as a shared Qodly Source string.
Depending on how the operation turns out, you would set this variable in your function and allow the page loader to monitor any changes so that the navigation would start automatically.
In your example, if the function’s condition is applied appropriately, navigate to the page “abc123” by returning it as a string.
No “else” required in the function, means stay in the current page, because there are some conditions applied by using “states”.
Warm regards.
Thanks Understand. Will use Page Loader.