I am busy with the validation plugin and i get it not working on my checkboxes and radio inputs. So can somewone help me with this how i can make it work? (i hope it can be done with the metadata just like the input field)
This is my JS:
$(".valid").validate({
meta: "validate",
errorPlacement: function(error, element) {
error.insertAfter(element);
}
});
And the HTML:
<form action="" class="valid">
<div class="row">
<label>Name</label>
<div class="right"><input type="text" value="" name="name" class="{validate:{required:true, messages:{required:'Please enter your name'}}}" /></div>
</div>
<div class="row">
<label>Checkboxes</label>
<div class="right">
<input type="checkbox" name="family" value="" id="family_one" checked="checked" class="required">
<label for="family_one">Check on</label>
<input type="checkbox" name="family" value="" id="family_two" class="required">
<label for="family_two">Check off</label>
</div>
</div>
<div class="row">
<label></label>
<div class="right">
<button type="submit"><span>Click me</span></button>
</div>
</div>
</form>
Form Check HTML checkboxes:
<div class="right">
<div class="custom-checkbox"><input type="checkbox" name="family" value="" id="third-check" class="require-one error"><label for="third-check">Check off</label></div>
<div class="custom-checkbox"><input type="checkbox" name="family" value="" id="fouth-check" class="require-one"><label for="fouth-check">Check off</label></div>
<div class="custom-checkbox"><input type="checkbox" name="family" value="" id="five-check" class="require-one"><label for="five-check" class="">Check off</label></div>
<div class="custom-checkbox"><input type="checkbox" name="family" value="" id="six-check" class="require-one">
<label for="checks" generated="true" class="error">Please check at least one box.</label>
<label for="six-check">Check off</label></div>
</div>
If you’re using the latest version of jQuery validate, you just have to add the class “required” to your element tags.
or
That would do for most cases, especially if you won’t be requiring a callback function.
Good luck!
EDIT:
Simpy call the validation function by using:
Just put an ID on the form so that you can call the function directly.
Cheers!
EDIT 2:
For checkboxes, try: