jQuery validation not working
jQuery validation is currently not functioning in CiviCRM. The validate
, cancel
, and required
classes on form elements are not triggering jQuery validation. The form still validates accurately, but this is server-side using Quickform.
I first noticed this in PR 17675, and I attempted to make a change there. However, that PR was delayed for unrelated reasons and there has been a lot of activity involving jQuery validate in the past few months.
-
PR 16488 attempted to apply the
required
attribute to required form elements. - PR 17929 rolled that back because it was invalid syntax.
-
PR 17937 adds the
required
attribute to individual radio options -
PR 18080 #1928 (closed) switches the
required
on each radio option to a class name rather than an attribute
@colemanw @mattwire @seamuslee @DaveD I'm opening a PR that's mostly that one commit detached from PR 17675.
There are two problems that remain even with the PR:
-
A required element inside a collapsed accordion won't be easily noticed. Server-side validation forces the accordion open, but the jQuery validation does not. However, I see no console errors from the result.
-
The behavior seems to vary from form to form. The New Contribution form is quite different from New Activity. The latter seems to never use jQuery Validator. Even besides looking for POST activity, you can see the different ways the validation appears: