hmpo-form-controller
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -21,2 +21,5 @@ var util = require('util'), | ||
this.Error = ErrorClass; | ||
this.formatter = dataFormatter(this.options.fields, this.options.defaultFormatters); | ||
this.validator = dataValidator(this.options.fields); | ||
}; | ||
@@ -49,2 +52,3 @@ | ||
} | ||
req.form = { values: values || {} }; | ||
debug('Rendering form for ' + req.path); | ||
@@ -102,11 +106,6 @@ if (_.isEmpty(this.options.fields) && this.options.next) { | ||
var formatter = dataFormatter(this.options.fields, this.options.defaultFormatters); | ||
var errors = {}; | ||
var validator = dataValidator(this.options.fields), | ||
errors = {}; | ||
_.each(req.form.values, function (value, key) { | ||
var emptyValue = formatter(key, ''); | ||
var error = validator(key, value, req.form.values, emptyValue); | ||
var error = this.validateField(key, req); | ||
if (error) { | ||
@@ -130,2 +129,6 @@ if (error.group) { | ||
}, | ||
validateField: function (key, req) { | ||
var emptyValue = this.formatter(key, ''); | ||
return this.validator(key, req.form.values[key], req.form.values, emptyValue); | ||
}, | ||
_process: function (req, res, callback) { | ||
@@ -132,0 +135,0 @@ req.form = { values: {} }; |
{ | ||
"name": "hmpo-form-controller", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -143,2 +143,14 @@ var Form = require('../../'); | ||
it('sets values to req.form.values', function () { | ||
Form.prototype.getValues.yields(null, { foo: 'bar' }); | ||
form.get(req, res, cb); | ||
req.form.values.should.eql({ foo: 'bar' }); | ||
}); | ||
it('defaults req.form.values to an empty object', function () { | ||
Form.prototype.getValues.yields(null); | ||
form.get(req, res, cb); | ||
req.form.values.should.eql({ }); | ||
}); | ||
it('calls form.render', function () { | ||
@@ -145,0 +157,0 @@ form.get(req, res, cb); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59083
1464