Cynthia
Cynthia

Reputation: 2150

mvc 3: disabling validation on selected fields

I have a need to disable validation on certain fields when certain events occur, so based on the suggestion in this thread: jQuery disable rule validation on a single field

I tried this:

$("form").validate({
   ignore: ".ignore"
})

But I am finding that it disables all validation on all fields, not just those with class="ignore".

Am I doing something wrong with this?

Upvotes: 1

Views: 2225

Answers (2)

Owen
Owen

Reputation: 4397

I'm currently doing it something like this

<button id="Submit" type="submit">Submit</button>

<script type="text/javascript">
    $("#Submit").on("click", function () {
        var validator = $("form").data('validator');
        validator.settings.ignore = ".ignore";
    });
</script>

Switch out .ignore for any jQuery selector or chain them up like ".ignore, input[type=hidden]"

Upvotes: 0

Ozzy
Ozzy

Reputation: 974

How about trying:

$('#CompaniesGridform').validate({
    ignore: ":disabled"
});

Upvotes: 1

Related Questions