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

hmpo-form-controller

Package Overview
Dependencies
Maintainers
4
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.11.0 to 0.12.0

14

lib/formatting/index.js

@@ -20,8 +20,18 @@ var _ = require('underscore');

return function (key, value) {
if (!Array.isArray(value)) {
value = [value];
}
if (_default && !(fields[key] && fields[key]['ignore-defaults'])) {
value = format(_default, value);
value = value.map(function (item) {
return format(_default, item);
});
}
if (fields[key] && fields[key].formatter) {
value = format(fields[key].formatter, value);
value = value.map(function (item) {
return format(fields[key].formatter, item);
});
}
if (value.length === 1) {
value = value[0];
}
return value;

@@ -28,0 +38,0 @@ };

@@ -75,3 +75,8 @@ var _ = require('underscore'),

}
if (!dependent || (dependent && !fields[dependent.field]) || (dependent && values[dependent.field] === dependent.value)) {
if (!dependent
|| (dependent && !fields[dependent.field])
|| (dependent && (Array.isArray(values[dependent.field])
? values[dependent.field].indexOf(dependent.value) > -1
: values[dependent.field] === dependent.value))
) {
return true;

@@ -78,0 +83,0 @@ } else {

10

lib/validation/validators.js

@@ -1,2 +0,3 @@

var moment = require('moment');
var moment = require('moment'),
_ = require('underscore');

@@ -49,3 +50,8 @@ // validator methods should return false (or falsy value) for *invalid* input

var values = [].slice.call(arguments, 1);
return values.length && (value === '' || values.indexOf(value) > -1);
if (!Array.isArray(value)) {
value = [value];
}
return values.length && _.every(value, function (item) {
return item === '' || values.indexOf(item) > -1;
});
},

@@ -52,0 +58,0 @@

{
"name": "hmpo-form-controller",
"version": "0.11.0",
"version": "0.12.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -327,2 +327,14 @@ var Form = require('../../');

it('applies formatter to array of values', function () {
var form = new Form({
template: 'index',
fields: {
field: { formatter: 'uppercase' }
}
});
req.body.field = ['value', 'another value'];
form.post(req, res, cb);
req.form.values.field.should.be.eql(['VALUE', 'ANOTHER VALUE']);
});
it('writes field values to req.form.values', function () {

@@ -1083,2 +1095,50 @@ form.post(req, res, cb);

describe('fields that are an array of values', function () {
beforeEach(function () {
form = new Form({
template: 'index',
fields: {
'field': {},
'field-2': {
validate: [
'required'
],
dependent: {
field: 'field',
value: 2
}
}
}
});
});
it('should be validated if the dependency exists and is an array containing the value', function () {
req = request({
form: {
values: {
'field': [1, 2, 3],
'field-2': ''
}
}
});
form._validate(req, res, cb);
cb.should.have.been.calledWith({
'field-2': new form.Error('field-2', { type: 'required' })
});
});
it('shouldn\'t be validated if the dependency exists and is an array which doesn\'t contain the value', function () {
req = request({
form: {
values: {
'field': [1, 3, 4],
'field-2': ''
}
}
});
form._validate(req, res, cb);
cb.should.have.been.calledWith();
});
});
});

@@ -1085,0 +1145,0 @@

@@ -196,3 +196,4 @@ var Validators = require('../../').validators;

['a', 'b', 'c', 'd'],
['a']
['a'],
[['a', 'b', 'c'], 'a', 'b']
];

@@ -212,3 +213,4 @@ _.each(inputs, function (i) {

[true, true],
['a', 'b', 'c', 'a']
['a', 'b', 'c', 'a'],
[['a', 'b'], 'a', 'b']
];

@@ -215,0 +217,0 @@ _.each(inputs, function (i) {

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