简体   繁体   中英

Asp.Net MVC Still validating hidden

I'm using

   $(document).ready(function () {
    $(":radio:eq(1)").click(function () {
        $("#JointApplicantInfo").show(1000);
    });

    $(":radio:eq(0)").click(function () {
        $("#JointApplicantInfo").hide(1000);
    });

});

to hide a div but when hidden the validations from

src="~/Scripts/jquery.validate.min.js">

src="~/Scripts/jquery.validate.unobtrusive.min.js">

are still happening even when hidden.

I am using [required] tags in the model to cause validation to happen.

I am unsure of how to make this not happen. I understand that it requires more scripting, but I am a novice and cannot figure it out.

You can override the jQuery validation and tell it to ignore hidden fields:

$(function() {
    var settngs = $.data($('form')[0], 'validator').settings;
    settings.ignore = ":not(:visible)";
});

Reference

Edit: I should add though, as others have commented, it is not really correct to annotate a field as [Required] if it is only required under certain circumstances.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM