5

I have a number of checkboxes listed on a page, the rendered html is as follows:

I need these grouped checkboxes to use validation so that at least one of the items is checked.

<input id="element_frm1167_8_1" name="test" class="element checkbox" type="checkbox" value="1" validate="required:true, minlength:2">
<input id="element_frm1167_8_2" name="test" class="element checkbox" type="checkbox" value="1" >
<input id="element_frm1167_8_3" name="test" class="element checkbox" type="checkbox" value="1" >

I've looked at an example from http://jquery.bassistance.de/validate/demo/radio-checkbox-select-demo.html

However, when I call form.Validate() I dont get any validation happening.

Please could someone point me in the right direction.

3 Answers 3

5

I'd say that chances are you haven't configured the metadata plugin (or included it at all). That's what handles taking the validate attribute in your checkbox, and turning that into rules for the validation plugin. To get what you want in a simpler way, you can just specify the rules directly in your validate call:

$('#myForm').validate({
 rules: {
    test: {
        required: true,
        minlength:2            
    }
 } 
});

See it in action here: http://jsfiddle.net/ryleyb/EWbED/

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Ryley - I hadnt included the metadata plugin correctly.
1

Try with naming your inputs like name="test[]" instead of name="test"

2 Comments

I don't see how that would be relevant? test is a legal name for an input isn't it?
'test' is legal. The brackets are only needed if posted to a PHP script.
0

Posting this for folks like me, who find this thread, and want to submit multiple values to PHP after validation (maybe almost everyone?). Include brackets in your form element names

<input id="element_frm1167_8_3" name="test[]" class="element checkbox" type="checkbox" value="1" >

and in the validation identifier

rules: {
  'test[]': {
    required: true,
    minlength:2            
  }
} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.