If you are using ASP.NET MVC Unobtrusive jQuery validation, you need to set the settings this way. This is due to how Microsoft actually calls jQuery validation. This should be safe to use inside the ready method.
Edit: See Corey's comment below before copying this. This is my original code.
$("form").data("validator").settings.ignore = ".data-val-ignore, :hidden, :disabled";
Then I just apply the .data-val-ignore class to things that are not checked.
Note that you probably want to add :hidden , which is actually the default ignore behavior defined in jquery.validate.js . I like to add :disabled too.
$.extend($.validator, { defaults: { messages: {}, groups: {}, rules: {}, errorClass: "error", validClass: "valid", errorElement: "label", focusInvalid: true, errorContainer: $([]), errorLabelContainer: $([]), onsubmit: true, ignore: ":hidden", // default for ignore in jquery.validate.js ignoreTitle: false, onfocusin: function( element, event ) { this.lastActive = element;
And finally, you might want to style it - especially useful when debugging.
.data-val-ignore { background: #eee; }
Simon_Weaver Feb 21 2018-12-23T00: 00Z
source share