Jquery-validation: How to disable/suspend and then re-enable validation

Created on 19 Apr 2013  路  9Comments  路  Source: jquery-validation/jquery-validation

I have a form that is used both for the entry of new data and also to view old data.

The rules for entering new data have changed; some of the old data no longer matches the new rules.

I want to be able to suspend validation when in view mode, but restore it when editing.

Currently, I use $("#'form").validate().currentForm="" to disable and $("#form").validate().currentForm = $("#form")[0] to reenable - surely there must be a cleaner way?

Documentation

Most helpful comment

Just use the "ignore" property to disable validation for some or even all elements. The default value is :hidden.

Two Excamples:
1) On initialization:

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

2) Dynamic way:

    $("form").validate().settings.ignore = "*";

Ignore is working like :not(). That means you can use several selectors by using a comma for separation.

But take into your account that the ignore property has to be set back to :hidden (default value) if you want to enable it dynamically.

I hope this is going to help you.

All 9 comments

Have you tried using the novalidate attribute on the form?

I have not tried that; is it dynamic? If I add it and remove it will jquery-validate recognise this?

Just use the "ignore" property to disable validation for some or even all elements. The default value is :hidden.

Two Excamples:
1) On initialization:

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

2) Dynamic way:

    $("form").validate().settings.ignore = "*";

Ignore is working like :not(). That means you can use several selectors by using a comma for separation.

But take into your account that the ignore property has to be set back to :hidden (default value) if you want to enable it dynamically.

I hope this is going to help you.

And so far as I know the _novalidate_ attribute is just for disabling the browsers html5 default validation. But maybe I am wrong :-)

And of course there are two further very convenient ways to disable form validation:

  1. add the html5 formnovalidate attribute to the submit button like <input type="submit" value="submit" formnovalidate> or
  2. add just the class cancel to the submit button

Labelled this as a documentation issue. Once #740 is resolved, I can work on that.

Wow I spend really hours for this problem. I didn't knew the ignore function was there. Now I only set the ignore to "*" for disabling everything in a form and when I want to enable it again, I set the ignore back to ":hidden" because that is the default.

When I saw this document, I immediately understood why my hidden (display: none;) fields weren't validated.

If none of the above worked for anyone, I used the following to remove validation on an element when I don't need it.

            $(element).parent().parent().removeClass("has-error");
            $(element).parent().parent().removeClass("has-success");
            $(element).next().remove();

I'm sorry for the lack of activity on this issue. Instead of leaving it open any longer, I decided to close old issues without trying to address them, to longer give the false impression that it will get addressed eventually.

To the reporter (or anyone else interested in this issue): If you're affected by the same issue, consider opening a new issue, with a testpage that shows the issue. Even better, try to fix the issue yourself, and improve the project by sending a pull request. This may seem daunting at first, but you'll likely learn some useful skills that you can apply elsewhere as well. And you can help keep this project alive. We've documented how to do these things, too. A patch is worth a thousand issues!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iamandycohen picture iamandycohen  路  5Comments

ricardopolo picture ricardopolo  路  8Comments

eproffit picture eproffit  路  4Comments

gimler picture gimler  路  5Comments

harkinj picture harkinj  路  8Comments