I have implemented custom server side validation for form fields, so when the user specifies a constraint, the field will be validated on form submit. I would like to have client side validation as well, if possible at constraint level so that all that it needs to be configured on a field is the constraint. Example: show an error bellow the field on blur event if the field is invalid. I know i can also provide the script clientvalidation.jsp, but i don't understand how this is working because adding the script seems to have no effect.
-
Are you asking in relation to form fields in a CQ5 author dialog, or form fields on a rendered page that end users see? – Shawn May 07 '15 at 16:49
-
@Shawn It's related to the form fields on a rendered page – Gabi May 07 '15 at 17:21
2 Answers
Since you are dealing with the rendered page, I recommend you add client side validation using a standard validation library, such as the jQuery validation plugin:
It does what you are looking for, such as this sort of thing:
I've used this in CQ pages. Check out the video on that page--it gives a good demo of how to do just what you are looking for. And check out the demos page:
This isn't the only validation option, so you could also consider others. I think the key is to just approach this problem as a typical HTML/JavaScript need rather than a CQ need.
Also see Best JavaScript solution for client-side form validation and interaction?
-
Yeah, this is what I'll probably do in the end. I'll see whether I use this plugin or another one. I was wondering if cq has support for this, therefore the question. – Gabi May 07 '15 at 18:43
You need to create a clientlib that contains JavaScript code that finds the proper form elements, attaches listeners to proper element events, performs the actual input validation within the listeners and finally displays appropriate messages on the page.

- 1,235
- 8
- 22