As above, how can I remove all of the required rules from a form using jQuery Validate?
This is what I have at present:
var settings = $('form').validate().settings;
//alert(settings.rules.toSource());
for (var i in settings.rules){
alert(i);
delete settings.rules.i;
// ^ not sure about how to do this properly,
// and how to just delete the 'required' rule and keep the rest intact
}
The function native to jQuery Validate returns an undefined error:
$("input, select, textarea").rules('remove','required');
To remove a certain data validation rule, select any cell with that rule, open the Data Validation dialog window, check the Apply these changes to all other cells with the same settings box, and then click the Clear All button.
The jquery validate plugin requires a form element to function, so you should have your form fields (no matter how few) contained inside a form. You can tell the validation plugin not to operate on form submission, then manually validate the form when the correct submit button is clicked.
And if you don't want to mess with validate's internal settings, you can use the public function in this way:
$('input, select, textarea').each(function() {
$(this).rules('remove', 'required');
});
Note that leaving out the second parameter (required) would remove all the rules, not just the "required".
As can sometimes be the case, I appear to have stumbled on the answer just after resorting to posting on here.
for (var i in settings.rules){
delete settings.rules[i].required;
}
Works.
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