james
james

Reputation: 23

JQuery Validation Plugin Question

I have seen several other posts with similar questions but nothing exactly like what I need to do. I need to have three checkboxes all with the same name but different ID's. When checkbox one is clicked then either 2 or 3 (either one) are required. But if the first checkbox is not clicked then none are required. This is the closest example of what I saw but not 100% there:

jquery validation rules

Any help is appreciated.

Upvotes: 1

Views: 161

Answers (1)

james
james

Reputation: 23

I found the answer. Well I was extremely over thinking this. At least two were always supposed to be required so this simple statement was all I needed:

{ required: true, minlength:2 }

Which I found here:

jQuery validate plugin with a minimum of 2 elements from a single array name

And then just added my message:

messages: {
    fieldname: {
        required:"Must select at least two of the three below options",
        minlength: jQuery.format("Must select at least two of the three below options")
    } 

Upvotes: 1

Related Questions