async-validate
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -75,2 +75,3 @@ var util = require('util'); | ||
var complete = function(results) { | ||
//console.log("got validation results %j", results); | ||
var i, field, errors = [], fields = {}; | ||
@@ -121,3 +122,5 @@ var add = function(e) { | ||
validator = function(callback) { | ||
var data = arguments.callee.data; | ||
var cb = function(errors) { | ||
//delete data.rule.validator; | ||
if(options.first) { | ||
@@ -128,3 +131,2 @@ return complete(errors); | ||
} | ||
var data = arguments.callee.data; | ||
//console.log("calling validator with messages %s", messages); | ||
@@ -163,6 +165,7 @@ data.rule.validator( | ||
} | ||
if(typeof rule.validator == 'function') { | ||
return 'function'; | ||
} | ||
if( !rule.type || !validators.hasOwnProperty(rule.type)) { | ||
//if(typeof rule.validator == 'function') { | ||
//return 'function'; | ||
//} | ||
if( !(typeof(rule.validator) == 'function') | ||
&& (!rule.type || !validators.hasOwnProperty(rule.type))) { | ||
throw new Error(util.format("Unknown rule type %s", rule.type)); | ||
@@ -169,0 +172,0 @@ } |
@@ -59,2 +59,4 @@ var util = require('util'); | ||
}else if(type && !(typeof(value) == rule.type)) { | ||
//console.log("checking type %s", type); | ||
//console.log("checking value %s", value); | ||
errors.push(error(rule, | ||
@@ -61,0 +63,0 @@ util.format(options.messages.types[type], rule.field, rule.type))); |
@@ -17,2 +17,3 @@ var rules = require('../rule'); | ||
rules.type(rule, value, source, errors, options); | ||
//console.log("got string errors %j", errors); | ||
rules.range(rule, value, source, errors, options); | ||
@@ -19,0 +20,0 @@ rules.pattern(rule, value, source, errors, options); |
{ | ||
"name": "async-validate", | ||
"description": "Asynchronous validation for object properties.", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "muji <noop@xpm.io>", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -149,2 +149,19 @@ var util = require('util'); | ||
); | ||
test("revalidate after failure", | ||
function() { | ||
var descriptor = { | ||
name: {type: "string", required: true, whitespace: true} | ||
} | ||
var validator = new schema(descriptor); | ||
validator.validate({name: ""}, function(errors, fields) { | ||
assert.equal(errors.length, 1); | ||
assert.equal( errors[0].message, "name cannot be empty"); | ||
validator.validate({name: "user"}, function(errors, fields) { | ||
console.log("after revalidation %j", errors); | ||
//assert.isNull(errors); | ||
//assert.isNull(fields); | ||
}); | ||
}); | ||
} | ||
); | ||
}); |
Sorry, the diff of this file is not supported yet
71578
1649