WS Form fires a number of different events during the lifecycle of a form. You can use these to run your own javascript when the event fires.
All WS Form events are passed the following parameters:
event– Event objectform_object– The form object (Form configuration).form_id– The form ID.instance_id– The instance ID of the form on the page. This is an integer that begins with 1. To learn more about instances, click here.form_el– The form element jQuery objectform_canvas_el– The form canvas element jQuery object
When using the WS Form WooCommerce extension, form_el will refer to the WooCommerce product form and form_canvas_el will refer to the form injected by WS Form.
Example of using the WS Form JavaScript are:
$(document).on('wsft-submit-before-ajax', function(event, form_object, form_id, instance_id, form_el, form_canvas_el) {
// Debug
console.log('Event type: ' + event.type + ' fired.');
console.log('Form ID: ' + form_id);
console.log('Instance ID: ' + instance_id);
// Get FormData object from form element
var form_data = new FormData(form_el[0]);
});
… where wsft-submit-before-ajax is the event type. In this example, the wsft-submit-before-ajax event fires immediately before we push the form data to our server side API.
Another example showing how to handle a lock event on the form. The form is locked when the form submit button is clicked to help prevent double clicks.
$(document).on('wsft-lock', function(event, form_object, form_id, instance_id) {
alert('Form ID ' + form_id + ' was locked!');
});
Events
The JavaScript events fired by WS Form at a document level are chronologically listed below:
| Name | Description | Trigger |
|---|---|---|
| Rendered | This fires when a form has finished rendering. | wsft-rendered |
| Tab Clicked | This fires when a tab is clicked or is moved to using conditional logic. | wsft-tab-clicked |
| Submit Before | This fires prior to the form being submitted (when submit button is clicked). | wsft-submit-before |
| Save Before | This fires prior to the form being saved (when save button is clicked). | wsft-save-before |
| Validation Before | This fires prior to the form being validated. | wsft-validate-before |
| Validation After | This fires when form validation has finished. | wsft-validate-after |
| Validation Success on Submit | This fires when validation was successful on submit. | wsft-submit-validate-success |
| Validation Success on Save | This fires when validation was successful on save. | wsft-save-validate-success |
| Validation Fail on Submit | This fires when validation failed on submit. | wsft-submit-validate-fail |
| Validation Fail on Save | This fires when validation failed on save. | wsft-save-validate-fail |
| Submit | This fires when the form data is about to be processed for submission. | wsft-submit |
| Save | This fires when the form data is about to be processed for saving. | wsft-save |
| Lock | This fires when the form is locked, just prior to the data being posted on a submit or save. | wsft-lock |
| Submit Ajax Before | This fires just before the form data is submitted to the WS Form server side API after the Submit button is clicked. | wsft-submit-before-ajax |
| Save Ajax Before | This fires just before the form data is submitted to the WS Form server side API after the Save button is clicked. | wsft-save-before-ajax |
| Complete | This fires when the form submit or save is completed. | wsft-complete |
| Submit Complete | This fires when the form submit is completed. | wsft-submit-complete |
| Save Complete | This fires when the form save is completed. | wsft-save-complete |
| Success | This fires when the form submit or save is successful. | wsft-success |
| Submit Success | This fires when the form submit is successful. | wsft-submit-success |
| Save Success | This fires when the form save is successful. | wsft-save-success |
| Error | This fires when the form submit or save encounters an error. | wsft-error |
| Submit Error | This fires when the form submit encounters an error. | wsft-submit-error |
| Save Error | This fires when the form save encounters an error. | wsft-save-error |
| Actions Start | This fires when the form actions start to run on the client side. | wsft-actions-start |
| Actions Finish | This fires when the form actions finish on the client side. | wsft-actions-finish |
| Unlock | This fires when the form is unlocked. | wsft-unlock |
| Reset Before | This fires when a form reset starts (when reset button is clicked). | wsft-reset-before |
| Reset Complete | This fires when a form reset completes. | wsft-reset-complete |
| Clear Before | This fires when a form clear starts (when clear button is clicked). | wsft-clear-before |
| Clear Complete | This fires when a form clear completes. | wsft-clear-complete |