Previous
TOC
Next
1. What will you learn
You will add data validation to the forms in the sample application.
2. Task Description
Add data validation to the search and the profile form. You will use mandatory
fields, minimum input length fields and custom validation fields.
3. Detailed Steps
1. Open the searchForm custom control and select
the searchBox.
2. On the validation tab specify the minimum
(3) and maximum (40) values for the search field.
3. Specify an error message

4. Test the pages

5. Open the profileForm custom control
6. Add “Required Field” to FirstName and LastName
and check the results
Add validation to the LastName field: must not be the same as FirstName
by going to the onClick event of the the Save button then the Client script
for the event. Enter the following script:
var firstName = dojo.byId("#{id:FirstName}");
var lastName = dojo.byId("#{id:LastName}");
if (firstName.value == lastName.value){
alert("The
First Name and Last Name must be different");
return false;
}else{
return true;
}
4. The Result

5. Things To Explore
- Use
a JavaScript regular expression (Google helps) to add a “Is this a valid
email” to an email field.
- Use
a requestScope variable isDraft to avoid validations when a document is
is in draft mode (make something up how draft mode works)
6. Further Readings