I am using the jQuery Validate plugin on my form, and was wondering how I would set every field to be required by default?
I am using a custom method called 'methodname' and I tried the following code to no avail:
$.validator.setDefaults({
methodname : true
});
Any ideas?
Thanks!
Quick'n'dirty fix:
$(document).ready(function(){
$('#myform input, #myform textarea').not([type="submit"]).addClass('required');
});
This should do the trick, and doesn't require any alteration to the markup:
$("#myform input, #myform textarea").each(function () {
$(this).rules("add", {
required: true // Or whatever rule you want
});
});
http://docs.jquery.com/Plugins/Validation/rules#rules.28.C2.A0.22add.22.2C.C2.A0rules_.29
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With