In this article, I will walk you through a simple Touch UI dialog field validation.
The validation framework has changed for Touch UI. This uses Granite Foundation Validation framework to validate the dialog fields.
If a text field has more than 9 characters, the dialog should show an error.
Step 1: Create a Dialog and inside the dialog, create a textfield using a resource type. Add a “class” property to the text field node as shown below.
Step 2: Inside the component:
- create a clientlibs folder (cq:ClientLibraryFolder) and add categories=”[cq.authoring.dialog]”
- create a js folder and js.txt file inside clientlibs folder
- Add a js (say validation.js) file inside js folder created #2.
- Include the js file into js.txt file.
add below code to js.txt
Example Structure below:
Note that the selector is the class value we added in the first step 1. The validator identifies your field with the help of the class.
Thats it, when you open the dialog and add more than 9 characters into the field, it should give an error.