0

In MVC3, there are a way to add or stop validation in a field depending on the value of a drop-drown list with JQuery? I have been trying with Fluent Validation, but with no luck.

2 Answers 2

1

Are you using unobtrusive validation? Is so, look at the html and you will see that there are some html5 attributes on your input, something like this:

<input name="product" id="product" data-val="true" data-val-required="Product is required" />

I suppose you could use jQuery to remove the data-val attribute and then the jQuery Validator will skip this item.

$("#product").data("val", false);

Well, that's my guess, try it yourself.

Sign up to request clarification or add additional context in comments.

Comments

0

you should use jQuery AddClass Rules

Create jQuery Class

 $.validator.addClassRules({
    Req: {
        required: true
    }
});

Validate the Filed by checking the selected value

$("#Selector").blur(function () {
    var Val= $("#Selector").val();

    if (Val == "Compare to the String") {

            $("#Selector").addClass("Req");
    }
    else {
        $("#Selector").removeClass("Req");
    }
});

1 Comment

this solution should work, but is not. I'm working on other workarounds that I will post if they works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.