Skip to content

Commit

Permalink
Require special validator before processing
Browse files Browse the repository at this point in the history
Will only perform the extra processing when the 'input-date' validator
is present in the array of validators for the field.
  • Loading branch information
daniel-ac-martin committed Jul 10, 2016
1 parent 480aa62 commit 514a51f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/date-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ util.inherits(DateController, Parent);
DateController.prototype.process = function process(req) {
_.each(this.options.fields, function processEach(v, k) {
if (
_.includes(v.validate, 'input-date') &&
(undefined !== req.body[k + '-year']) &&
(undefined !== req.body[k + '-month']) &&
(undefined !== req.body[k + '-day'])
Expand All @@ -21,7 +22,7 @@ DateController.prototype.process = function process(req) {

var processField = function processField(key, validators) {
this.options.fields[key] = {
validate: childValidators.concat(validators),
validate: _.union(childValidators, validators),
dependent: v.dependent
};

Expand Down
4 changes: 2 additions & 2 deletions test/spec/spec.date-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Date Controller', function () {
beforeEach(function () {
key = 'date-field';
options = { template: 'index', fields: {} };
options.fields[key] = {}
options.fields[key] = { validate: ['input-date'] }
form = new DateController(options);
sinon.stub(form, 'get').yields();
sinon.stub(form, 'post').yields();
Expand Down Expand Up @@ -283,7 +283,7 @@ describe('Date Controller', function () {
beforeEach(function () {
key = 'date-field';
options = { template: 'index', fields: {} };
options.fields[key] = { validate: ['required'] }
options.fields[key] = { validate: ['required', 'input-date'] }
form = new DateController(options);
sinon.stub(form, 'get').yields();
sinon.stub(form, 'post').yields();
Expand Down

0 comments on commit 514a51f

Please sign in to comment.