JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.0/jquery.validate.min.js"></script>
<form class="my_form" method="post" action="#">
<div class="error-container">
<ul>
</ul>
</div><!--error-container-->
<p><label>My checkbox 1</label>
<input class="my_checkbox_group" id="my_checkbox_1"
name="my_checkbox_1[]" type="checkbox" value="Yes" /></p>
<p><label>My checkbox 2</label>
<input class="my_checkbox_group" id="my_checkbox_2"
name="my_checkbox_2[]" type="checkbox" value="Yes" /></p>
<p><label>My checkbox 3</label>
<input class="my_checkbox_group" id="my_checkbox_3"
name="my_checkbox_3[]" type="checkbox" value="Yes" /></p>
<p>
<label>My text field 1</label>
<input class="required" id="my_text_field_1" name="my_text_field_1" type="text" value="" /></p>
<input type="submit" value="Submit" />
</form>
CSS
input.error { background: #fdf3f3; border: 1px solid #ff3333; color: #ff3333; }
.error-container { background: #fdf3f3; border: 1px solid #ff3333; clear: both; display: none; overflow: auto; padding: 10px; }
.error-container ul { margin-bottom: 0; }
.error-container label { float: none; font-weight: normal!important; width: auto; }
JavaScript
$(document).ready(function () {
$.validator.addMethod("checkboxrule", function (value, element) {
return ($('#my_checkbox_1').is(':checked') || $('#my_checkbox_2').is(':checked') || $('#my_checkbox_3').is(':checked'))
}, "Select at least one of these three");
$('.my_form').validate({ // initialize the plugin
errorContainer: ".error-container",
errorLabelContainer: ".error-container ul",
wrapper: "li",
focusInvalid: false,
ignore: [],
/*groups: {
somename: "my_checkbox_1[] my_checkbox_2[] my_checkbox_3[]"
},*/
rules: {
'my_checkbox_1[]': {
checkboxrule: true
},
'my_checkbox_2[]': {
checkboxrule: true
},
'my_checkbox_3[]': {
checkboxrule: true
}
},
/*success: function() {
$('.error-container').hide();
},*/
submitHandler: function (form) { // for demo
alert('valid form submitted'); // for demo
return false; // for demo
}
});
});