Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

This article is suitable for developers

For complete flexibility, we allow clients and developers to add any custom code to pages that they wish. To help with this, we provide JavaScript “page hooks” as a way to integrate this custom code.

When a form is submitted, we use event.preventDefault() to stop the submit. We also run the validation (and other processes) asynchronously, using promises. After that, if everything is validated, then the page is submitted.

There are three page hooks that help standardize ‘event interception’ and to help custom scripts to follow a more formal methodology.

The page hooks are enOnValidate, enOnSubmit and enOnError.

These three functions have been placed in global scope (i.e on the window object) and when present, our page JavaScript will call them during the submission process.

Function Description
enOnValidate Called during validation – any validation fails will prevent the page submitting. A function that can return true to allow processing to continue, return false to prevent processing, or return a Promise that will only allow the processing to continue once the Promise is resolved.
enOnSubmit Called when validation has successfully completed and the page is about to be submitted. A function that can return true to allow processing to continue, return false to prevent processing, or return a Promise that will only allow the processing to continue once the Promise is resolved.
enOnError Called when the client side validation fails. The return value is ignored.

For enOnValidate and enOnSubmit, both callbacks work the same – they are a function that can return true to allow processing to continue, return false to prevent processing, or return a Promise that will only allow the processing to continue once the Promise is resolved.

Avoid defining the same hook multiple times, as only the most recently defined will be run.

enOnSubmit examples

Basic example to prevent submit:

 

Example using promises to prevent submit

 

enOnValidate examples

Example of custom validation

 

Example of AJAX validation

 

enOnError examples

enOnError is a hook that is called when the client side validation fails. Like enOnSubmit and enOnValidate, it should be set on the window object so it is in global scope.

The return value is ignored.

Example of ‘on Error’

 

 

  • No labels