jQuery validation: Indicate that at least one element in a group is required
15 Apr 2009 edit
I had a need today to indicate that at least one of a set of input fields was required. I was hoping there was a direct way to do this in the jQuery validation plugin; while the method isn't quite as straightforward as I was wishing for, it's still fairly simple.
To start with, I put
class="required_group" on each of the elements in the group. Then, I added a custom validation method:
... a custom class rule to take advantage of the new method:
... and finally a custom message for the new method:
What I'd love to see is a way to specify a dependent group without using a custom class rule, but I'm not sure what this would look like, as all validation rules are either keyed off an element's class or the presence of the element's name in the rules object. Thoughts? I'm open to the possibility that there's a far better way to solve this --