Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hmpo-form-controller

Package Overview
Dependencies
Maintainers
3
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hmpo-form-controller - npm Package Compare versions

Comparing version 0.2.5 to 0.3.0

2

lib/validation/index.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc