hmpo-form-controller
Advanced tools
Comparing version 0.2.5 to 0.3.0
@@ -45,3 +45,3 @@ var _ = require('underscore'), | ||
} | ||
if (!dependent || (dependent && values[dependent.field] === dependent.value)) { | ||
if (!dependent || (dependent && !fields[dependent.field]) || (dependent && values[dependent.field] === dependent.value)) { | ||
return true; | ||
@@ -48,0 +48,0 @@ } else { |
{ | ||
"name": "hmpo-form-controller", | ||
"version": "0.2.5", | ||
"version": "0.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -613,3 +613,4 @@ var Form = require('../../'); | ||
var form, oldFormatters; | ||
var form, oldFormatters, req, res, cb; | ||
beforeEach(function () { | ||
@@ -631,2 +632,11 @@ oldFormatters = _.clone(Form.formatters); | ||
}); | ||
res = {}; | ||
cb = sinon.stub(); | ||
}); | ||
afterEach(function () { | ||
Form.formatters = oldFormatters; | ||
}); | ||
it('should clean the values with an appropriately formatted empty value if a dependency is not met', function () { | ||
form = new Form({ | ||
@@ -663,10 +673,3 @@ template: 'index', | ||
}); | ||
}); | ||
afterEach(function () { | ||
Form.formatters = oldFormatters; | ||
}); | ||
it('should clean the values with an appropriately formatted empty value if a dependency is not met', function () { | ||
var req = request({ | ||
req = request({ | ||
flash: sinon.stub(), | ||
@@ -681,4 +684,3 @@ form: { | ||
} | ||
}), res = {}; | ||
var cb = sinon.stub(); | ||
}); | ||
@@ -698,2 +700,108 @@ form._validate(req, res, cb); | ||
it('should be validated if the dependency exists in the step\'s fields and the value matches', function () { | ||
form = new Form({ | ||
template: 'index', | ||
fields: { | ||
'is-thing': { | ||
validate: [ | ||
'required' | ||
] | ||
}, | ||
'is-thing-b': { | ||
validate: [ | ||
'required' | ||
], | ||
dependent: { | ||
field: 'is-thing', | ||
value: 'true' | ||
} | ||
} | ||
} | ||
}); | ||
req = request({ | ||
form: { | ||
values: { | ||
'is-thing': 'true', | ||
'is-thing-b': '' | ||
} | ||
} | ||
}); | ||
form._validate(req, res, cb); | ||
cb.should.have.been.calledWith({ | ||
'is-thing-b': new form.Error('is-thing-b', { type: 'required' }) | ||
}); | ||
}); | ||
it('should be validated if the dependency doesn\'t exist in the step\'s fields', function () { | ||
form = new Form({ | ||
template: 'index', | ||
fields: { | ||
'is-thing': { | ||
validate: [ | ||
'required' | ||
] | ||
}, | ||
'is-thing-b': { | ||
validate: [ | ||
'required' | ||
], | ||
dependent: { | ||
field: 'is-not-a-thing', | ||
value: 'true' | ||
} | ||
} | ||
} | ||
}); | ||
req = request({ | ||
form: { | ||
values: { | ||
'is-thing': 'true', | ||
'is-thing-b': '' | ||
} | ||
} | ||
}); | ||
form._validate(req, res, cb); | ||
cb.should.have.been.calledWith({ | ||
'is-thing-b': new form.Error('is-thing-b', { type: 'required' }) | ||
}); | ||
}); | ||
it('shouldn\'t be validated if the dependency exists but the value doesn\'t match', function () { | ||
form = new Form({ | ||
template: 'index', | ||
fields: { | ||
'is-thing': { | ||
validate: [ | ||
'required' | ||
] | ||
}, | ||
'is-thing-b': { | ||
validate: [ | ||
'required' | ||
], | ||
dependent: { | ||
field: 'is-thing', | ||
value: 'false' | ||
} | ||
} | ||
} | ||
}); | ||
req = request({ | ||
form: { | ||
values: { | ||
'is-thing': 'false', | ||
'is-thing-b': '' | ||
} | ||
} | ||
}); | ||
form._validate(req, res, cb); | ||
cb.should.have.been.calledWith(); | ||
}); | ||
}); | ||
@@ -700,0 +808,0 @@ |
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
65754
1625
1