In most cases, the validation process will be called automatically as needed when you define 'form submission' or 'ajax submission' actions on your page.
In some cases however you may need to manually trigger the built-in validation functionality from your own script functions, and so WebMaker provides a number of functions that can be used to easily do this.
The important functions are:
Each of these functions returns a boolean value indicating the success of the validation, so will be true if no errors were found.
It is common to use these functions in a script fragment like:
In some cases however you may need to manually trigger the built-in validation functionality from your own script functions, and so WebMaker provides a number of functions that can be used to easily do this.
The important functions are:
hyf.validation.validateForm() | This function will validate all the fields on the whole page, and will show any errors found using the error display options specified for the page. |
hyf.validation.validateContainer(container) | This function will validate all the fields contained within the provided container, and will show any errors found using the error display options specified for the page. The container parameter must be an HTML component (eg div) on the page. For example, to validate all the fields within a group called mygroup, you could use hyf.validation.validateContainer(document.getElementById('mygroup')); |
hyf.validation.validateField(field) | This function will validate the specified field, and will display an error if appropriate. The field parameter must be an HTML edit component (eg text box) on the page. If you wanted to validate a field called myfield, you could use hyf.validation.validateField(document.getElementById('myfield')); |
Each of these functions returns a boolean value indicating the success of the validation, so will be true if no errors were found.
It is common to use these functions in a script fragment like:
if (hyf.validation.validateForm())
{
//validation was successful so perform the required functionality here
}