Skip to content

v2.1.0

Choose a tag to compare

@CharlGottschalk CharlGottschalk released this 25 Nov 10:14
· 12 commits to master since this release

Added test cancellation:

By default, ApproveJS will continue testing every rule and return all tests' error messages. For example:

var rules = {
   required: true,
   email: true
};

var result = approve.value('', rules);

The above code will check whether the value is present (required = true) and whether it is a valid email address (email = true). Should the value fail the required rule, ApproveJS will continue and also test the email rule, returning errors for both tests.

It makes sense though, that if the value fails the required test, that it will automatically fail the email test, so you might want to stop testing and return only the errors for the failed required test. For this we use the stop property which will stop all testing after the first failed rule, i.e.

var rules = {
   stop: true,
   required: true,
   email: true
};

var result = approve.value('', rules);

Now, should the required rule fail, ApproveJS will stop all testing and return only the error messages for the required rule.

Note that rules are tested in the order in which they appear in the rule object, i.e.

var rules = {
   stop: true,
   required: true,
   email: true
};

In the code above, required will be tested first, and email second whereas in the code below, email will be tested first, and required second.

var rules = {
   stop: true,
   email: true,
   required: true
};