JSFiddle - React, Tailwind, and code Playground
by Sami Mahmal
HTML
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>
<form id="myform">
<input type="text" name="one-x.child" /><br />
<input type="text" name="two-x.child" /><br />
<input type="checkbox" name="ContentObjectAttribute_ezselect_selected_array_176450[]" /><span> Toto </span><br />
<input type="checkbox" name="ContentObjectAttribute_ezselect_selected_array_176450[]" /><span> Toto 2 </span><br />
<input type="submit" />
</form>
JavaScript
$(document).ready(function() {
$("#myform").validate({
errorElement: "p",
errorClass: "form-error",
submitHandler: function(form) { // for demo only
return false;
}
});
// the following method must come AFTER .validate()
$("input[name='ContentObjectAttribute_ezselect_selected_array_176450[]']").each(function() {
$(this).rules('add', {
required: true,
messages: {
required: "Required input",
minlength: jQuery.format("At least {0} characters are necessary")
}
});
});
});