Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC validation attributes and Jquery

I have mvc attributes on fields that validate on submit. Although these attributes are on these fields, I want to override their validation if I click a SaveDraft button. Right now I try to disable validation of the field using jquery rules but the mvc attributes seem to override the rules. How can I make the MVC attributes ignore validation if I click a different button? Here is an example of what I want to do onClick but it does not work.


 $(".btnsave").click(function () {
        $('#WizForm').validate(

        {
            rules:
        {
            Title: false,
            Description: false  //dont validate this field onclick

        },
          }).Form();
});
like image 276
Nate Avatar asked Jun 29 '11 15:06

Nate


1 Answers

You can use following to remove all validation rules from an element

$('#Password').rules('remove')

To remove specific rule use

$('#Password').rules('remove', 'required')

And to add rule

$("#Password").rules("add", { minlength: 2 });

Finally to check current rules

$('#Password').rules()

Note If your selector returns more than one element only the first element is used by rules method

Check out here for more

Also make sure that you have latest version. more people got in trouble with IE and jQuery-validation-1.8

like image 167
Beygi Avatar answered Oct 12 '22 08:10

Beygi