In the previous post in this series about getting started with ValidateThis!, my validation framework for ColdFusion objects, we looked at how to very quickly get up and running with the framework, and how to use it to perform server-side validations for our objects. In this post we'll look at enabling client-side validations for those same business rules.
Step 1 - The JS Files
- jquery-1.3.2.min.js - the jQuery library
- jquery.validate.pack.js - the jQuery Validation Plugin
- jquery.field.min.js - the jQuery Field Plugin
The latest versions of those files ship with VT and can be found in /ValidateThis/client/jQuery/js. So, you'll need to copy those files to a web accessible folder (e.g., /js/), if you don't already have a copy of them from whence they can be accessed.
As discussed above, those files need to be loaded into your web page. You can do that manually, using code similar to this:
Or you can ask VT to load the files for you, using a convenience method. Assuming you have access to VT in a variable, such as application.ValidateThis (as discussed in the previous post), you can simply call getInitializationScript(), passing in the objectType:
VT will generate the code required to load all of the libraries for you, which cfhtmlhead then places into your head tag.
Similar to the above, you can simply call getValidationScript(), passing in the objectType:
And it's as simple as that - your page will now provide client-side validations!
In the next post I'll look at some of the other validation types that are currently available in the framework.
As always, if you have any questions or interest in following the progress of VT, I invite you to join the ValidateThis! Google Group.