Overview
Stopping a lightbox form submission is useful in order to validate that the input fields have appropriate values.
Process
In the Custom JS (Boxes), there are a few Event Triggers where this can be accomplished.
- Before form validation
- After form validation
- Before submit
These three Event Triggers are unique from all the other ones. They allow you to return different "types" to achieve different results. Specifically, if you return one of the following statements.
Return false
Returning false simply halts execution and prevents the form from being submitted. If you return false for the Event Trigger Before Form Validation then the normal validation will not run and the form will not be submitted. But if you return false After Form Validation then the normal validation will run, but your custom js function will only run if it makes it past the normal validation. But if it makes it that far, since you are returning false, it will halt execution and the form will not be submitted. And finally, if you return false Before Submit then the normal validation will run, but the form will not be submitted.
Return "some error message"
In this case, if you return a string, it will be displayed as an error message. This is a way to display a custom validation failure message. It works exactly like returning "false" above. But in this case, it also displays an error message to the user.
Return anObject
If your custom javascript code returns an object, the object will be used as the "form" data for the submission. The existing form data is overwritten. Important to note!! ==> the custom js functions receive 3 input parameters as follows: (api, s, x) which you can reference within your custom js function code. The parameters api and s will always be the same for all of the custom js Event Trigger functions. However, in the case of the unique 3 "event trigger" functions above, the "x" parameter is an object that will contain the current form data. So let's say you want to add a "password" field in "custom_1" here is how you would do that in the custom function "Before Submit":
x.custom_1 = "some_random_pw";
x.additional_field = "anything";
return x;
In the example above, x is modified and then returned. When you return an object like this, it instructs the form submission process to use that object instead of the original form data object.
Return true or return
This type of return value will allow the Primer widget to continue with the normal flow of the form submission process.
Comments
0 comments
Please sign in to leave a comment.