async-validate
Advanced tools
Comparing version
@@ -205,2 +205,16 @@ ## Guide | ||
To signal that an internal processing error has occured pass an Error to the callback, for example: | ||
```javascript | ||
function id(cb) { | ||
this.model.findById(this.value, function(err, id) { | ||
if(err) { | ||
return cb(err); | ||
} | ||
// validate id for error conditions | ||
cb(); | ||
}); | ||
} | ||
``` | ||
### Plugins | ||
@@ -239,2 +253,29 @@ | ||
The important point to remember is that for helper methods assign to `this` and for static rule functions (located by `type`) assign to `main` in the plugin. | ||
Helper method: | ||
```javascript | ||
module.exports = function() { | ||
// create a helper method on the prototype | ||
// of the class used for static function scope | ||
this.helper = function(value) { | ||
return value; | ||
} | ||
} | ||
``` | ||
Static method: | ||
```javascript | ||
module.exports = function() { | ||
this.main.id = function id(cb) { | ||
// use helper method | ||
var val = this.helper(this.value); | ||
// implement validation for `id` type | ||
cb(); | ||
} | ||
} | ||
``` | ||
### Rule Properties | ||
@@ -241,0 +282,0 @@ |
@@ -143,3 +143,2 @@ var iterator = require('./iterator') | ||
errors: [], | ||
options: options, | ||
messages: options.messages | ||
@@ -153,2 +152,7 @@ }); | ||
function onValidate(err) { | ||
if(err) { | ||
return callback(err); | ||
} | ||
var i | ||
@@ -230,15 +234,12 @@ , errors = validator.errors; | ||
}, function(err, result) { | ||
// bail on first error | ||
if(options.first && errors && errors.length) { | ||
return complete(err, errors, options, cb); | ||
} | ||
// bail on first error | ||
if(options.first && errors && errors.length) { | ||
return complete(err, errors, options, cb); | ||
} | ||
callback(err, errors); | ||
}) | ||
} | ||
} | ||
// invoke rule validation function | ||
rule.validator.call(validator, onValidate); | ||
@@ -245,0 +246,0 @@ |
{ | ||
"name": "async-validate", | ||
"description": "Asynchronous validation for node and the browser", | ||
"version": "0.7.4", | ||
"version": "0.7.5", | ||
"author": "muji <noop@xpm.io>", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -308,2 +308,16 @@ Table of Contents | ||
To signal that an internal processing error has occured pass an Error to the callback, for example: | ||
```javascript | ||
function id(cb) { | ||
this.model.findById(this.value, function(err, id) { | ||
if(err) { | ||
return cb(err); | ||
} | ||
// validate id for error conditions | ||
cb(); | ||
}); | ||
} | ||
``` | ||
### Plugins | ||
@@ -342,2 +356,29 @@ | ||
The important point to remember is that for helper methods assign to `this` and for static rule functions (located by `type`) assign to `main` in the plugin. | ||
Helper method: | ||
```javascript | ||
module.exports = function() { | ||
// create a helper method on the prototype | ||
// of the class used for static function scope | ||
this.helper = function(value) { | ||
return value; | ||
} | ||
} | ||
``` | ||
Static method: | ||
```javascript | ||
module.exports = function() { | ||
this.main.id = function id(cb) { | ||
// use helper method | ||
var val = this.helper(this.value); | ||
// implement validation for `id` type | ||
cb(); | ||
} | ||
} | ||
``` | ||
### Rule Properties | ||
@@ -344,0 +385,0 @@ |
134262
1.86%79
1.28%2901
0.9%791
5.47%