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

forms

Package Overview
Dependencies
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

forms - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

.editorconfig

11

CHANGELOG.md

@@ -0,1 +1,12 @@

1.3.1 / 2019-05-03
===================
* [Fix] length validators should work with both strings and numbers (#204)
* [Fix] ES3: use `array.prototype.{some,every}` instead of `Array#{some,every}`
* [Fix] ES3: use `reduce` instead of `Array#reduce`
* [Deps] update `async`, `formidable`, `is`, `object-keys`, `object.assign`, `qs`, `reduce`
* [Dev Deps] update `tape`, `eslint`, `@ljharb/eslint-config`, `nsp`, `covert`
* [Dev Deps] remove `testling`, `jscs`
* [Tests] use `npx aud` instead of `nsp` or `npm audit` with hoops
* [Tests] up to `node` `v12.1`, `v11.14`, `v10.15`, `v9.11`, `v8.15`, `v7.10`, `v6.17`, `v4.9`; use `nvm install-latest-npm`; run coverage tests but allow failure, for now
1.3.0 / 2016-11-15

@@ -2,0 +13,0 @@ ===================

11

lib/fields.js
'use strict';
var is = require('is');
var some = require('array.prototype.some');
var async = require('async');
var assign = require('object.assign');
var forms = require('./forms');
var tag = require('./tag');
var is = require('is');
var async = require('async');
var validators = require('./validators');
var coerceArray = function (arr) {
return is.array(arr) && arr.length > 0 ? arr : [];
};
var assign = require('object.assign');
var nameSeparatorRegExp = /[_-]/g;

@@ -31,3 +34,3 @@

b.validate = function (form, callback) {
var forceValidation = (b.validators || []).some(function (validator) {
var forceValidation = some(b.validators || [], function (validator) {
return validator.forceValidation;

@@ -34,0 +37,0 @@ });

@@ -10,3 +10,5 @@ 'use strict';

var assign = require('object.assign');
var every = require('array.prototype.every');
var keys = require('object-keys');
var reduce = require('reduce');

@@ -42,4 +44,4 @@ exports.widgets = require('./widgets');

});
b.data = keys(b.fields).reduce(function (a, k) {
a[k] = b.fields[k].data;
b.data = reduce(b.fields, function (a, bField, k) {
a[k] = bField.data;
return a;

@@ -61,3 +63,3 @@ }, {});

var form = this;
return keys(form.fields).every(function (k) {
return every(keys(form.fields), function (k) {
var field = form.fields[k];

@@ -111,5 +113,5 @@ if (is.fn(field.isValid)) { return field.isValid(); }

return keys(form.fields).reduce(function (html, k) {
return reduce(form.fields, function (html, field, k) {
var kname = is.string(name) ? name + '[' + k + ']' : k;
return html + form.fields[k].toHTML(kname, iterator);
return html + field.toHTML(kname, iterator);
}, '');

@@ -116,0 +118,0 @@ }

@@ -20,9 +20,9 @@ 'use strict';

var str = coerceToString(value);
return hChars.test(str) ?
str.replace(rAmp, '&')
return hChars.test(str)
? str.replace(rAmp, '&')
.replace(rLt, '<')
.replace(rGt, '>')
.replace(rApos, ''')
.replace(rQuot, '"') :
str;
.replace(rQuot, '"')
: str;
};

@@ -29,0 +29,0 @@

@@ -6,2 +6,3 @@ 'use strict';

var keys = require('object-keys');
var reduce = require('reduce');

@@ -56,3 +57,3 @@ // generates a string for common HTML tag attributes

var safeTagName = htmlEscape(tagName);
var attrsHTML = !is.array(attrsMap) ? attrs(attrsMap) : attrsMap.reduce(function (html, map) {
var attrsHTML = !is.array(attrsMap) ? attrs(attrsMap) : reduce(attrsMap, function (html, map) {
return html + attrs(map);

@@ -59,0 +60,0 @@ }, '');

@@ -6,2 +6,3 @@ 'use strict';

var trim = require('string.prototype.trim');
var every = require('array.prototype.every');

@@ -115,3 +116,3 @@ var format = function format(message) {

return function (form, field, callback) {
if (field.data.length >= val) {
if (String(field.data).length >= val) {
callback();

@@ -127,3 +128,3 @@ } else {

return function (form, field, callback) {
if (field.data.length <= val) {
if (String(field.data).length <= val) {
callback();

@@ -139,3 +140,3 @@ } else {

return function (form, field, callback) {
if (field.data.length >= min && field.data.length <= max) {
if (String(field.data).length >= min && String(field.data).length <= max) {
callback();

@@ -197,3 +198,3 @@ } else {

var parts = field.data ? field.data.split('-') : [];
var allNumbers = parts.every(function (part) { return numberRegex.test(part); });
var allNumbers = every(parts, function (part) { return numberRegex.test(part); });
var date = allNumbers && parts.length === 3 ? new Date(parts[0], parts[1] - 1, parts[2]) : invalidDate;

@@ -200,0 +201,0 @@ if (!isNaN(date.getTime())) {

'use strict';
var is = require('is');
var keys = require('object-keys');
var reduce = require('reduce');
var some = require('array.prototype.some');
var tag = require('./tag');

@@ -12,5 +13,5 @@

var getUserAttrs = function (opt) {
return keys(opt).reduce(function (attrs, k) {
return reduce(opt, function (attrs, option, k) {
if ((ignoreAttrs.indexOf(k) === -1 && legalAttrs.indexOf(k) > -1) || dataRegExp.test(k) || ariaRegExp.test(k)) {
attrs[k] = opt[k];
attrs[k] = option;
}

@@ -53,11 +54,13 @@ return attrs;

var isSelected = function (value, choice) {
return value && (is.array(value) ? value.some(choiceValueEquals.bind(null, choice)) : choiceValueEquals(value, choice));
return value && (is.array(value)
? some(value, function (v) { return choiceValueEquals(v, choice); })
: choiceValueEquals(value, choice));
};
var renderChoices = function (choices, renderer) {
return choices.reduce(function (partialRendered, choice) {
return reduce(choices, function (partialRendered, choice) {
var isNested = is.array(choice[1]);
var renderData = isNested ?
{ isNested: true, label: choice[0], choices: choice[1] } :
{ isNested: false, value: choice[0], label: choice[1] };
var renderData = isNested
? { isNested: true, label: choice[0], choices: choice[1] }
: { isNested: false, value: choice[0], label: choice[1] };
return partialRendered + renderer(renderData);

@@ -77,3 +80,3 @@ }, '');

var unifyChoiceArray = function (arrayChoices, currentLevel) {
return arrayChoices.reduce(function (result, choice) {
return reduce(arrayChoices, function (result, choice) {
if (!is.array(choice) || choice.length !== 2) {

@@ -94,4 +97,3 @@ throw new TypeError('choice must be array with two elements');

var unifyChoiceObject = function (objectChoices, currentLevel) {
return keys(objectChoices).reduce(function (result, key) {
var label = objectChoices[key];
return reduce(objectChoices, function (result, label, key) {
if (isScalar(label)) {

@@ -98,0 +100,0 @@ result.push([key, label]);

{
"name": "forms",
"version": "1.3.0",
"version": "1.3.1",
"description": "An easy way to create, parse, and validate forms",

@@ -29,30 +29,27 @@ "main": "./index",

"tests-only": "tape test/*.js",
"posttest": "npm run security",
"test-browser": "testling",
"posttest": "npx aud",
"coverage": "covert test/*.js",
"coverage-quiet": "covert --quiet test/*.js",
"lint": "npm run jscs && npm run eslint && evalmd *.md",
"eslint": "eslint test/*.js lib/*.js example/simple.js example/complex.js",
"jscs": "jscs test/*.js lib/*.js example/simple.js example/complex.js",
"security": "nsp check"
"prelint": "evalmd *.md",
"lint": "eslint test/*.js lib/*.js example/simple.js example/complex.js"
},
"dependencies": {
"async": "^2.1.2",
"qs": "^6.3.0",
"formidable": "^1.0.17",
"is": "^3.2.0",
"object.assign": "^4.0.4",
"object-keys": "^1.0.11",
"array.prototype.every": "^1.0.0",
"array.prototype.some": "^1.0.0",
"async": "^2.6.2",
"formidable": "^1.2.1",
"is": "^3.3.0",
"object-keys": "^1.1.1",
"object.assign": "^4.1.0",
"qs": "^6.7.0",
"reduce": "^1.0.2",
"string.prototype.trim": "^1.1.2"
},
"devDependencies": {
"tape": "^4.6.2",
"tape-dom": "^0.0.12",
"testling": "^1.7.1",
"covert": "^1.1.0",
"jscs": "^3.0.7",
"eslint": "^3.10.2",
"@ljharb/eslint-config": "^8.0.0",
"nsp": "^2.6.2",
"evalmd": "^0.0.17"
"@ljharb/eslint-config": "^12.2.1",
"covert": "^1.1.1",
"eslint": "^4.19.1",
"evalmd": "^0.0.17",
"tape": "^4.10.1",
"tape-dom": "^0.0.12"
},

@@ -88,2 +85,1 @@ "license": "MIT",

}

@@ -192,6 +192,6 @@ 'use strict';

stringField.toHTML('fieldname'),
'<div class="field">' +
'<label for="id_fieldname">Fieldname</label>' +
'<input type="text" name="fieldname" id="id_fieldname" />' +
'</div>'
'<div class="field">'
+ '<label for="id_fieldname">Fieldname</label>'
+ '<input type="text" name="fieldname" id="id_fieldname" />'
+ '</div>'
);

@@ -216,6 +216,6 @@ var f = fields.string();

}).toHTML('fieldname'),
'<div class="field custom-field-class1 custom-field-class2">' +
'<label for="id_fieldname" class="custom-label-class1 custom-label-class2">Fieldname</label>' +
'<input type="text" name="fieldname" id="id_fieldname" />' +
'</div>'
'<div class="field custom-field-class1 custom-field-class2">'
+ '<label for="id_fieldname" class="custom-label-class1 custom-label-class2">Fieldname</label>'
+ '<input type="text" name="fieldname" id="id_fieldname" />'
+ '</div>'
);

@@ -240,6 +240,6 @@ t.end();

fields.number().toHTML('fieldname'),
'<div class="field">' +
'<label for="id_fieldname">Fieldname</label>' +
'<input type="text" name="fieldname" id="id_fieldname" />' +
'</div>'
'<div class="field">'
+ '<label for="id_fieldname">Fieldname</label>'
+ '<input type="text" name="fieldname" id="id_fieldname" />'
+ '</div>'
);

@@ -265,6 +265,6 @@ t.end();

fields['boolean']().toHTML('fieldname'),
'<div class="field">' +
'<label for="id_fieldname">Fieldname</label>' +
'<input type="checkbox" name="fieldname" id="id_fieldname" value="on" />' +
'</div>'
'<div class="field">'
+ '<label for="id_fieldname">Fieldname</label>'
+ '<input type="checkbox" name="fieldname" id="id_fieldname" value="on" />'
+ '</div>'
);

@@ -271,0 +271,0 @@ t.end();

@@ -110,14 +110,14 @@ 'use strict';

f.toHTML(),
'<div class="field">' +
'<label for="id_field1">Field1</label>' +
'<input type="text" name="field1" id="id_field1" value="1" />' +
'</div>' +
'<div class="field">' +
'<label for="id_field2">Field2</label>' +
'<input type="text" name="field2" id="id_field2" value="2" />' +
'</div>' +
'<div class="field">' +
'<label for="id_field3">Field3</label>' +
'<input type="text" name="field3" id="id_field3" value="0" />' +
'</div>'
'<div class="field">'
+ '<label for="id_field1">Field1</label>'
+ '<input type="text" name="field1" id="id_field1" value="1" />'
+ '</div>'
+ '<div class="field">'
+ '<label for="id_field2">Field2</label>'
+ '<input type="text" name="field2" id="id_field2" value="2" />'
+ '</div>'
+ '<div class="field">'
+ '<label for="id_field3">Field3</label>'
+ '<input type="text" name="field3" id="id_field3" value="0" />'
+ '</div>'
);

@@ -146,12 +146,12 @@ t.end();

f.toHTML(),
'<div class="field error">' +
'<p class="error_msg">validation error 1</p>' +
'<label for="id_field1">Field1</label>' +
'<input type="text" name="field1" id="id_field1" value="1" />' +
'</div>' +
'<div class="field error">' +
'<p class="error_msg">validation error 2</p>' +
'<label for="id_field2">Field2</label>' +
'<input type="text" name="field2" id="id_field2" value="2" />' +
'</div>'
'<div class="field error">'
+ '<p class="error_msg">validation error 1</p>'
+ '<label for="id_field1">Field1</label>'
+ '<input type="text" name="field1" id="id_field1" value="1" />'
+ '</div>'
+ '<div class="field error">'
+ '<p class="error_msg">validation error 2</p>'
+ '<label for="id_field2">Field2</label>'
+ '<input type="text" name="field2" id="id_field2" value="2" />'
+ '</div>'
);

@@ -475,6 +475,6 @@ t.end();

f.toHTML(),
'<div class="field">' +
'<label for="id_fieldname">Fieldname</label>' +
'<input type="text" name="fieldname" id="id_fieldname" />' +
'</div>'
'<div class="field">'
+ '<label for="id_fieldname">Fieldname</label>'
+ '<input type="text" name="fieldname" id="id_fieldname" />'
+ '</div>'
);

@@ -488,6 +488,6 @@ t.end();

f.toHTML(),
'<div class="field required">' +
'<label for="id_fieldname">Fieldname</label>' +
'<input type="text" name="fieldname" id="id_fieldname" />' +
'</div>'
'<div class="field required">'
+ '<label for="id_fieldname">Fieldname</label>'
+ '<input type="text" name="fieldname" id="id_fieldname" />'
+ '</div>'
);

@@ -503,6 +503,6 @@ t.end();

f.toHTML(),
'<div class="field">' +
'<label for="id_name">Name</label>' +
'<input type="text" name="name" id="id_name" value="val" />' +
'</div>'
'<div class="field">'
+ '<label for="id_name">Name</label>'
+ '<input type="text" name="name" id="id_name" value="val" />'
+ '</div>'
);

@@ -525,8 +525,8 @@ t.end();

f.toHTML(),
'<div class="field error">' +
'<p class="error_msg">validation error</p>' +
'<label for="id_field_name">Field name</label>' +
'<input type="text" name="field_name" id="id_field_name" ' +
'value="val" />' +
'</div>'
'<div class="field error">'
+ '<p class="error_msg">validation error</p>'
+ '<label for="id_field_name">Field name</label>'
+ '<input type="text" name="field_name" id="id_field_name" '
+ 'value="val" />'
+ '</div>'
);

@@ -533,0 +533,0 @@ t.end();

@@ -13,10 +13,10 @@ 'use strict';

f.toHTML(),
'<div class="field">' +
'<label for="id_field1">Field1</label>' +
'<input type="text" name="field1" id="id_field1" />' +
'</div>' +
'<div class="field">' +
'<label for="id_field2">Field2</label>' +
'<input type="text" name="field2" id="id_field2" />' +
'</div>'
'<div class="field">'
+ '<label for="id_field1">Field1</label>'
+ '<input type="text" name="field1" id="id_field1" />'
+ '</div>'
+ '<div class="field">'
+ '<label for="id_field2">Field2</label>'
+ '<input type="text" name="field2" id="id_field2" />'
+ '</div>'
);

@@ -23,0 +23,0 @@ t.end();

@@ -11,6 +11,6 @@ 'use strict';

f.toHTML(forms.render[tag]),
'<' + tag + ' class="field">' +
'<label for="id_fieldname">Fieldname</label>' +
'<input type="text" name="fieldname" id="id_fieldname" />' +
'</' + tag + '>'
'<' + tag + ' class="field">'
+ '<label for="id_fieldname">Fieldname</label>'
+ '<input type="text" name="fieldname" id="id_fieldname" />'
+ '</' + tag + '>'
);

@@ -24,6 +24,6 @@ t.end();

f.toHTML(forms.render[tag]),
'<' + tag + ' class="field">' +
'<input type="text" name="fieldname" id="id_fieldname" />' +
'<label for="id_fieldname">Fieldname</label>' +
'</' + tag + '>'
'<' + tag + ' class="field">'
+ '<input type="text" name="fieldname" id="id_fieldname" />'
+ '<label for="id_fieldname">Fieldname</label>'
+ '</' + tag + '>'
);

@@ -46,7 +46,7 @@ t.end();

f.toHTML(forms.render[tag]),
'<' + tag + ' class="field error">' +
'<input type="text" name="fieldname" id="id_fieldname" value="val" />' +
'<label for="id_fieldname">Fieldname</label>' +
'<p class="error_msg">validation error after field</p>' +
'</' + tag + '>'
'<' + tag + ' class="field error">'
+ '<input type="text" name="fieldname" id="id_fieldname" value="val" />'
+ '<label for="id_fieldname">Fieldname</label>'
+ '<p class="error_msg">validation error after field</p>'
+ '</' + tag + '>'
);

@@ -61,6 +61,6 @@ });

f.toHTML(forms.render[tag]),
'<' + tag + ' class="field required">' +
'<label for="id_fieldname">Fieldname</label>' +
'<input type="text" name="fieldname" id="id_fieldname" />' +
'</' + tag + '>'
'<' + tag + ' class="field required">'
+ '<label for="id_fieldname">Fieldname</label>'
+ '<input type="text" name="fieldname" id="id_fieldname" />'
+ '</' + tag + '>'
);

@@ -76,6 +76,6 @@ t.end();

f.toHTML(forms.render[tag]),
'<' + tag + ' class="field">' +
'<label for="id_name">Name</label>' +
'<input type="text" name="name" id="id_name" value="val" />' +
'</' + tag + '>'
'<' + tag + ' class="field">'
+ '<label for="id_name">Name</label>'
+ '<input type="text" name="name" id="id_name" value="val" />'
+ '</' + tag + '>'
);

@@ -104,12 +104,12 @@ t.end();

f.toHTML(forms.render[tag]),
'<' + tag + ' class="field error">' +
'<p class="error_msg">validation error</p>' +
'<label for="id_field_name">Field name</label>' +
'<input type="text" name="field_name" id="id_field_name" value="val" />' +
'</' + tag + '>' +
'<' + tag + ' class="field error">' +
'<label for="id_field_name_error_after">Field name error after</label>' +
'<input type="text" name="field_name_error_after" id="id_field_name_error_after" value="foo" />' +
'<p class="error_msg">validation error after field</p>' +
'</' + tag + '>'
'<' + tag + ' class="field error">'
+ '<p class="error_msg">validation error</p>'
+ '<label for="id_field_name">Field name</label>'
+ '<input type="text" name="field_name" id="id_field_name" value="val" />'
+ '</' + tag + '>'
+ '<' + tag + ' class="field error">'
+ '<label for="id_field_name_error_after">Field name error after</label>'
+ '<input type="text" name="field_name_error_after" id="id_field_name_error_after" value="foo" />'
+ '<p class="error_msg">validation error after field</p>'
+ '</' + tag + '>'
);

@@ -137,10 +137,10 @@ });

f.toHTML(forms.render[tag]),
'<' + tag + ' class="field error">' +
'<label for="id_field_name">Field name</label>' +
'<input type="text" name="field_name" id="id_field_name" value="val" />' +
'</' + tag + '>' +
'<' + tag + ' class="field error">' +
'<label for="id_field_name_error_after">Field name error after</label>' +
'<input type="text" name="field_name_error_after" id="id_field_name_error_after" value="foo" />' +
'</' + tag + '>'
'<' + tag + ' class="field error">'
+ '<label for="id_field_name">Field name</label>'
+ '<input type="text" name="field_name" id="id_field_name" value="val" />'
+ '</' + tag + '>'
+ '<' + tag + ' class="field error">'
+ '<label for="id_field_name_error_after">Field name error after</label>'
+ '<input type="text" name="field_name_error_after" id="id_field_name_error_after" value="foo" />'
+ '</' + tag + '>'
);

@@ -171,9 +171,9 @@

f.toHTML(forms.render[tag]),
'<' + tag + ' class="field">' +
'<fieldset class="test3 test4">' +
'<legend class="test1 test2">Fieldname</legend>' +
'<input type="checkbox" name="fieldname" id="id_fieldname_one" value="one" />' +
'<label for="id_fieldname_one">item one</label>' +
'</fieldset>' +
'</' + tag + '>'
'<' + tag + ' class="field">'
+ '<fieldset class="test3 test4">'
+ '<legend class="test1 test2">Fieldname</legend>'
+ '<input type="checkbox" name="fieldname" id="id_fieldname_one" value="one" />'
+ '<label for="id_fieldname_one">item one</label>'
+ '</fieldset>'
+ '</' + tag + '>'
);

@@ -194,9 +194,9 @@ t.end();

f.toHTML(forms.render[tag]),
'<' + tag + ' class="field">' +
'<fieldset class="test3 test4">' +
'<legend class="test1 test2">Fieldname</legend>' +
'<input type="radio" name="fieldname" id="id_fieldname_one" value="one" />' +
'<label for="id_fieldname_one">item one</label>' +
'</fieldset>' +
'</' + tag + '>'
'<' + tag + ' class="field">'
+ '<fieldset class="test3 test4">'
+ '<legend class="test1 test2">Fieldname</legend>'
+ '<input type="radio" name="fieldname" id="id_fieldname_one" value="one" />'
+ '<label for="id_fieldname_one">item one</label>'
+ '</fieldset>'
+ '</' + tag + '>'
);

@@ -210,6 +210,6 @@ t.end();

f.toHTML(forms.render[tag]),
'<' + tag + ' class="field">' +
'<label for="custom-id">Fieldname</label>' +
'<input type="text" name="fieldname" id="custom-id" />' +
'</' + tag + '>'
'<' + tag + ' class="field">'
+ '<label for="custom-id">Fieldname</label>'
+ '<input type="text" name="fieldname" id="custom-id" />'
+ '</' + tag + '>'
);

@@ -223,6 +223,6 @@ t.end();

f.toHTML(forms.render[tag]),
'<' + tag + ' class="field">' +
'<label>Fieldname</label>' +
'<input type="text" name="fieldname" />' +
'</' + tag + '>'
'<' + tag + ' class="field">'
+ '<label>Fieldname</label>'
+ '<input type="text" name="fieldname" />'
+ '</' + tag + '>'
);

@@ -236,5 +236,5 @@ t.end();

f.toHTML(forms.render[tag]),
'<' + tag + ' class="field">' +
'<input type="hidden" name="fieldname" id="id_fieldname" />' +
'</' + tag + '>'
'<' + tag + ' class="field">'
+ '<input type="hidden" name="fieldname" id="id_fieldname" />'
+ '</' + tag + '>'
);

@@ -253,8 +253,8 @@ t.end();

f.toHTML(forms.render.table),
'<tr class="field">' +
'<th><label for="id_fieldname">Fieldname</label></th>' +
'<td>' +
'<input type="text" name="fieldname" id="id_fieldname" />' +
'</td>' +
'</tr>'
'<tr class="field">'
+ '<th><label for="id_fieldname">Fieldname</label></th>'
+ '<td>'
+ '<input type="text" name="fieldname" id="id_fieldname" />'
+ '</td>'
+ '</tr>'
);

@@ -268,8 +268,8 @@ t.end();

f.toHTML(forms.render.table),
'<tr class="field required">' +
'<th><label for="id_fieldname">Fieldname</label></th>' +
'<td>' +
'<input type="text" name="fieldname" id="id_fieldname" />' +
'</td>' +
'</tr>'
'<tr class="field required">'
+ '<th><label for="id_fieldname">Fieldname</label></th>'
+ '<td>'
+ '<input type="text" name="fieldname" id="id_fieldname" />'
+ '</td>'
+ '</tr>'
);

@@ -285,8 +285,8 @@ t.end();

f.toHTML(forms.render.table),
'<tr class="field">' +
'<th><label for="id_name">Name</label></th>' +
'<td>' +
'<input type="text" name="name" id="id_name" value="val" />' +
'</td>' +
'</tr>'
'<tr class="field">'
+ '<th><label for="id_name">Name</label></th>'
+ '<td>'
+ '<input type="text" name="name" id="id_name" value="val" />'
+ '</td>'
+ '</tr>'
);

@@ -315,16 +315,16 @@ t.end();

f.toHTML(forms.render.table),
'<tr class="field error">' +
'<th><label for="id_field_name">Field name</label></th>' +
'<td>' +
'<p class="error_msg">validation error</p>' +
'<input type="text" name="field_name" id="id_field_name" value="val" />' +
'</td>' +
'</tr>' +
'<tr class="field error">' +
'<th><label for="id_field_name_error_after">Field name error after</label></th>' +
'<td>' +
'<input type="text" name="field_name_error_after" id="id_field_name_error_after" value="foo" />' +
'<p class="error_msg">validation error after field</p>' +
'</td>' +
'</tr>'
'<tr class="field error">'
+ '<th><label for="id_field_name">Field name</label></th>'
+ '<td>'
+ '<p class="error_msg">validation error</p>'
+ '<input type="text" name="field_name" id="id_field_name" value="val" />'
+ '</td>'
+ '</tr>'
+ '<tr class="field error">'
+ '<th><label for="id_field_name_error_after">Field name error after</label></th>'
+ '<td>'
+ '<input type="text" name="field_name_error_after" id="id_field_name_error_after" value="foo" />'
+ '<p class="error_msg">validation error after field</p>'
+ '</td>'
+ '</tr>'
);

@@ -352,14 +352,14 @@ });

f.toHTML(forms.render.table),
'<tr class="field error">' +
'<th><label for="id_field_name">Field name</label></th>' +
'<td>' +
'<input type="text" name="field_name" id="id_field_name" value="val" />' +
'</td>' +
'</tr>' +
'<tr class="field error">' +
'<th><label for="id_field_name_error_after">Field name error after</label></th>' +
'<td>' +
'<input type="text" name="field_name_error_after" id="id_field_name_error_after" value="foo" />' +
'</td>' +
'</tr>'
'<tr class="field error">'
+ '<th><label for="id_field_name">Field name</label></th>'
+ '<td>'
+ '<input type="text" name="field_name" id="id_field_name" value="val" />'
+ '</td>'
+ '</tr>'
+ '<tr class="field error">'
+ '<th><label for="id_field_name_error_after">Field name error after</label></th>'
+ '<td>'
+ '<input type="text" name="field_name_error_after" id="id_field_name_error_after" value="foo" />'
+ '</td>'
+ '</tr>'
);

@@ -366,0 +366,0 @@

@@ -36,7 +36,7 @@ 'use strict';

t.equal(html,
'<select name="field" id="id_field">' +
'<option value="">Make a choice</option>' +
'<option value="choice1">Choice 1</option>' +
'<option value="choice2">Choice 2</option>' +
'</select>'
'<select name="field" id="id_field">'
+ '<option value="">Make a choice</option>'
+ '<option value="choice1">Choice 1</option>'
+ '<option value="choice2">Choice 2</option>'
+ '</select>'
);

@@ -43,0 +43,0 @@

@@ -211,3 +211,3 @@ 'use strict';

test('minlength', function (t) {
t.plan(2);
t.plan(4);
validators.minlength(5, 'Enter at least %s characters.')('form', { data: '1234' }, function (tooShortError) {

@@ -217,9 +217,15 @@ t.equal(tooShortError, 'Enter at least 5 characters.');

t.equal(err, undefined);
t.end();
});
});
validators.minlength(5, 'Enter at least %s characters.')('form', { data: 12345 }, function (err) {
t.equal(err, undefined);
});
validators.minlength(5, 'Enter at least %s characters.')('form', { data: 1234 }, function (err) {
t.equal(err, 'Enter at least 5 characters.');
});
t.end();
});
test('maxlength', function (t) {
t.plan(2);
t.plan(4);
validators.maxlength(5)('form', { data: '123456' }, function (tooLongError) {

@@ -229,9 +235,15 @@ t.equal(tooLongError, 'Please enter no more than 5 characters.');

t.equal(err, undefined);
t.end();
});
});
validators.maxlength(5, 'Please enter no more than 5 characters.')('form', { data: 12345 }, function (err) {
t.equal(err, undefined);
});
validators.maxlength(5, 'Please enter no more than 5 characters.')('form', { data: 123456 }, function (err) {
t.equal(err, 'Please enter no more than 5 characters.');
});
t.end();
});
test('rangelength', function (t) {
t.plan(4);
t.plan(8);
validators.rangelength(2, 4, 'Enter between %s and %s characters.')('form', { data: '12345' }, function (err) {

@@ -249,2 +261,14 @@ t.equal(err, 'Enter between 2 and 4 characters.');

});
validators.rangelength(2, 4, 'Enter between %s and %s characters.')('form', { data: 12345 }, function (err) {
t.equal(err, 'Enter between 2 and 4 characters.');
});
validators.rangelength(2, 4)('form', { data: 1 }, function (err) {
t.equal(err, 'Please enter a value between 2 and 4 characters long.');
});
validators.rangelength(2, 4)('form', { data: 12 }, function (err) {
t.equal(err, undefined);
});
validators.rangelength(2, 4)('form', { data: 1234 }, function (err) {
t.equal(err, undefined);
});
t.end();

@@ -251,0 +275,0 @@ });

@@ -94,6 +94,6 @@ 'use strict';

}),
'<select name="name" id="id_name">' +
'<option value="val1">text1</option>' +
'<option value="val2">text2</option>' +
'</select>'
'<select name="name" id="id_name">'
+ '<option value="val1">text1</option>'
+ '<option value="val2">text2</option>'
+ '</select>'
);

@@ -110,6 +110,6 @@ var widget = forms.widgets.select({ classes: ['one', 'two'] });

}),
'<select name="name" id="someid" class="one two">' +
'<option value="val1">text1</option>' +
'<option value="val2" selected="selected">text2</option>' +
'</select>'
'<select name="name" id="someid" class="one two">'
+ '<option value="val1">text1</option>'
+ '<option value="val2" selected="selected">text2</option>'
+ '</select>'
);

@@ -166,12 +166,12 @@ t.equal(widget.type, 'select');

}),
'<select name="name" id="id_name">' +
'<option value="val1">text1</option>' +
'<option value="val2">text2</option>' +
'<optgroup label="text3">' +
'<option value="val3">text4</option>' +
'<option value="val4">text5</option>' +
'<option value="val5">text6</option>' +
'</optgroup>' +
'<option value="val6">text7</option>' +
'</select>'
'<select name="name" id="id_name">'
+ '<option value="val1">text1</option>'
+ '<option value="val2">text2</option>'
+ '<optgroup label="text3">'
+ '<option value="val3">text4</option>'
+ '<option value="val4">text5</option>'
+ '<option value="val5">text6</option>'
+ '</optgroup>'
+ '<option value="val6">text7</option>'
+ '</select>'
);

@@ -237,6 +237,6 @@ st.end();

});
var expectedHTML = '<select name="name" id="someid" class="one two">' +
'<option value="1">one</option>' +
'<option value="2" selected="selected">two</option>' +
'</select>';
var expectedHTML = '<select name="name" id="someid" class="one two">'
+ '<option value="1">one</option>'
+ '<option value="2" selected="selected">two</option>'
+ '</select>';
st.equal(html, expectedHTML);

@@ -268,3 +268,3 @@ st.end();

'<textarea name="name" id="id_name">Inside&lt;/textarea&gt;Escaped the textarea!</textarea>'
);
);

@@ -290,8 +290,8 @@ st.end();

w.toHTML('name', field),
'<input type="checkbox" name="name" id="id_name_one" value="one" />' +
'<label for="id_name_one">Item one</label>' +
'<input type="checkbox" name="name" id="id_name_two" value="two" checked="checked" />' +
'<label for="id_name_two">Item two</label>' +
'<input type="checkbox" name="name" id="id_name_three" value="three" />' +
'<label for="id_name_three">Item three</label>'
'<input type="checkbox" name="name" id="id_name_one" value="one" />'
+ '<label for="id_name_one">Item one</label>'
+ '<input type="checkbox" name="name" id="id_name_two" value="two" checked="checked" />'
+ '<label for="id_name_two">Item two</label>'
+ '<input type="checkbox" name="name" id="id_name_three" value="three" />'
+ '<label for="id_name_three">Item three</label>'
);

@@ -304,8 +304,8 @@ st.equal(w.type, 'multipleCheckbox');

widget.toHTML('name', field),
'<input type="checkbox" name="name" id="id_name_one" value="one" />' +
'<label for="id_name_one" class="test1 test2 test3">Item one</label>' +
'<input type="checkbox" name="name" id="id_name_two" value="two" checked="checked" />' +
'<label for="id_name_two" class="test1 test2 test3">Item two</label>' +
'<input type="checkbox" name="name" id="id_name_three" value="three" />' +
'<label for="id_name_three" class="test1 test2 test3">Item three</label>'
'<input type="checkbox" name="name" id="id_name_one" value="one" />'
+ '<label for="id_name_one" class="test1 test2 test3">Item one</label>'
+ '<input type="checkbox" name="name" id="id_name_two" value="two" checked="checked" />'
+ '<label for="id_name_two" class="test1 test2 test3">Item two</label>'
+ '<input type="checkbox" name="name" id="id_name_three" value="three" />'
+ '<label for="id_name_three" class="test1 test2 test3">Item three</label>'
);

@@ -344,8 +344,8 @@ st2.end();

var html = w.toHTML('name', field);
var expectedHTML = '<input type="checkbox" name="name" id="id_name_1" value="1" />' +
'<label for="id_name_1">one</label>' +
'<input type="checkbox" name="name" id="id_name_2" value="2" checked="checked" />' +
'<label for="id_name_2">two</label>' +
'<input type="checkbox" name="name" id="id_name_3" value="3" />' +
'<label for="id_name_3">three</label>';
var expectedHTML = '<input type="checkbox" name="name" id="id_name_1" value="1" />'
+ '<label for="id_name_1">one</label>'
+ '<input type="checkbox" name="name" id="id_name_2" value="2" checked="checked" />'
+ '<label for="id_name_2">two</label>'
+ '<input type="checkbox" name="name" id="id_name_3" value="3" />'
+ '<label for="id_name_3">three</label>';
t2.equal(html, expectedHTML);

@@ -361,8 +361,8 @@ t2.end();

var html = w.toHTML('name', field);
var expectedHTML = '<input type="checkbox" name="name" id="id_name_1" value="1" checked="checked" />' +
'<label for="id_name_1">one</label>' +
'<input type="checkbox" name="name" id="id_name_2" value="2" checked="checked" />' +
'<label for="id_name_2">two</label>' +
'<input type="checkbox" name="name" id="id_name_3" value="3" />' +
'<label for="id_name_3">three</label>';
var expectedHTML = '<input type="checkbox" name="name" id="id_name_1" value="1" checked="checked" />'
+ '<label for="id_name_1">one</label>'
+ '<input type="checkbox" name="name" id="id_name_2" value="2" checked="checked" />'
+ '<label for="id_name_2">two</label>'
+ '<input type="checkbox" name="name" id="id_name_3" value="3" />'
+ '<label for="id_name_3">three</label>';
t2.equal(html, expectedHTML);

@@ -390,8 +390,8 @@ t2.end();

w.toHTML('name', field),
'<input type="checkbox" name="name" id="id_name_one" value="one" />' +
'<label for="id_name_one">Item one</label>' +
'<input type="checkbox" name="name" id="id_name_two" value="two" checked="checked" />' +
'<label for="id_name_two">Item two</label>' +
'<input type="checkbox" name="name" id="id_name_three" value="three" checked="checked" />' +
'<label for="id_name_three">Item three</label>'
'<input type="checkbox" name="name" id="id_name_one" value="one" />'
+ '<label for="id_name_one">Item one</label>'
+ '<input type="checkbox" name="name" id="id_name_two" value="two" checked="checked" />'
+ '<label for="id_name_two">Item two</label>'
+ '<input type="checkbox" name="name" id="id_name_three" value="three" checked="checked" />'
+ '<label for="id_name_three">Item three</label>'
);

@@ -414,8 +414,8 @@ t.equal(forms.widgets.multipleCheckbox().type, 'multipleCheckbox');

w.toHTML('name', field),
'<input type="radio" name="name" id="id_name_one" value="one" />' +
'<label for="id_name_one">Item one</label>' +
'<input type="radio" name="name" id="id_name_two" value="two" checked="checked" />' +
'<label for="id_name_two">Item two</label>' +
'<input type="radio" name="name" id="id_name_three" value="three" />' +
'<label for="id_name_three">Item three</label>'
'<input type="radio" name="name" id="id_name_one" value="one" />'
+ '<label for="id_name_one">Item one</label>'
+ '<input type="radio" name="name" id="id_name_two" value="two" checked="checked" />'
+ '<label for="id_name_two">Item two</label>'
+ '<input type="radio" name="name" id="id_name_three" value="three" />'
+ '<label for="id_name_three">Item three</label>'
);

@@ -450,8 +450,8 @@ t.equal(forms.widgets.multipleRadio().type, 'multipleRadio');

var html = w.toHTML('name', boundValueField);
var expectedHTML = '<input type="radio" name="name" id="id_name_1" value="1" />' +
'<label for="id_name_1">one</label>' +
'<input type="radio" name="name" id="id_name_2" value="2" checked="checked" />' +
'<label for="id_name_2">two</label>' +
'<input type="radio" name="name" id="id_name_3" value="3" />' +
'<label for="id_name_3">three</label>';
var expectedHTML = '<input type="radio" name="name" id="id_name_1" value="1" />'
+ '<label for="id_name_1">one</label>'
+ '<input type="radio" name="name" id="id_name_2" value="2" checked="checked" />'
+ '<label for="id_name_2">two</label>'
+ '<input type="radio" name="name" id="id_name_3" value="3" />'
+ '<label for="id_name_3">three</label>';
t2.equal(html, expectedHTML);

@@ -467,8 +467,8 @@ t2.end();

var html = w.toHTML('name', boundValuesField);
var expectedHTML = '<input type="radio" name="name" id="id_name_1" value="1" />' +
'<label for="id_name_1">one</label>' +
'<input type="radio" name="name" id="id_name_2" value="2" checked="checked" />' +
'<label for="id_name_2">two</label>' +
'<input type="radio" name="name" id="id_name_3" value="3" checked="checked" />' +
'<label for="id_name_3">three</label>';
var expectedHTML = '<input type="radio" name="name" id="id_name_1" value="1" />'
+ '<label for="id_name_1">one</label>'
+ '<input type="radio" name="name" id="id_name_2" value="2" checked="checked" />'
+ '<label for="id_name_2">two</label>'
+ '<input type="radio" name="name" id="id_name_3" value="3" checked="checked" />'
+ '<label for="id_name_3">three</label>';
t2.equal(html, expectedHTML);

@@ -485,8 +485,8 @@ t2.end();

widget.toHTML('name', field),
'<input type="radio" name="name" id="id_name_one" value="one" />' +
'<label for="id_name_one" class="test1 test2 test3">Item one</label>' +
'<input type="radio" name="name" id="id_name_two" value="two" checked="checked" />' +
'<label for="id_name_two" class="test1 test2 test3">Item two</label>' +
'<input type="radio" name="name" id="id_name_three" value="three" />' +
'<label for="id_name_three" class="test1 test2 test3">Item three</label>'
'<input type="radio" name="name" id="id_name_one" value="one" />'
+ '<label for="id_name_one" class="test1 test2 test3">Item one</label>'
+ '<input type="radio" name="name" id="id_name_two" value="two" checked="checked" />'
+ '<label for="id_name_two" class="test1 test2 test3">Item two</label>'
+ '<input type="radio" name="name" id="id_name_three" value="three" />'
+ '<label for="id_name_three" class="test1 test2 test3">Item three</label>'
);

@@ -511,8 +511,8 @@ st.end();

w.toHTML('name', field),
'<input type="radio" name="name" id="id_name_one" value="one" />' +
'<label for="id_name_one">Item one</label>' +
'<input type="radio" name="name" id="id_name_two" value="two" checked="checked" />' +
'<label for="id_name_two">Item two</label>' +
'<input type="radio" name="name" id="id_name_three" value="three" checked="checked" />' +
'<label for="id_name_three">Item three</label>'
'<input type="radio" name="name" id="id_name_one" value="one" />'
+ '<label for="id_name_one">Item one</label>'
+ '<input type="radio" name="name" id="id_name_two" value="two" checked="checked" />'
+ '<label for="id_name_two">Item two</label>'
+ '<input type="radio" name="name" id="id_name_three" value="three" checked="checked" />'
+ '<label for="id_name_three">Item three</label>'
);

@@ -531,6 +531,6 @@ t.equal(forms.widgets.multipleRadio().type, 'multipleRadio');

}),
'<select name="name" id="id_name" multiple="multiple">' +
'<option value="val1">text1</option>' +
'<option value="val2">text2</option>' +
'</select>'
'<select name="name" id="id_name" multiple="multiple">'
+ '<option value="val1">text1</option>'
+ '<option value="val2">text2</option>'
+ '</select>'
);

@@ -547,7 +547,7 @@ t.equal(

}),
'<select name="name" id="someid" multiple="multiple" class="one two">' +
'<option value="val1">text1</option>' +
'<option value="val2" selected="selected">text2</option>' +
'<option value="val3" selected="selected">text3</option>' +
'</select>'
'<select name="name" id="someid" multiple="multiple" class="one two">'
+ '<option value="val1">text1</option>'
+ '<option value="val2" selected="selected">text2</option>'
+ '<option value="val3" selected="selected">text3</option>'
+ '</select>'
);

@@ -569,7 +569,7 @@ t.equal(forms.widgets.multipleSelect().type, 'multipleSelect');

});
var expectedHTML = '<select name="name" id="someid" multiple="multiple" class="one two">' +
'<option value="1">text1</option>' +
'<option value="2" selected="selected">text2</option>' +
'<option value="3">text3</option>' +
'</select>';
var expectedHTML = '<select name="name" id="someid" multiple="multiple" class="one two">'
+ '<option value="1">text1</option>'
+ '<option value="2" selected="selected">text2</option>'
+ '<option value="3">text3</option>'
+ '</select>';
t2.equal(html, expectedHTML);

@@ -589,7 +589,7 @@ t2.end();

});
var expectedHTML = '<select name="name" id="someid" multiple="multiple" class="one two">' +
'<option value="1">text1</option>' +
'<option value="2" selected="selected">text2</option>' +
'<option value="3" selected="selected">text3</option>' +
'</select>';
var expectedHTML = '<select name="name" id="someid" multiple="multiple" class="one two">'
+ '<option value="1">text1</option>'
+ '<option value="2" selected="selected">text2</option>'
+ '<option value="3" selected="selected">text3</option>'
+ '</select>';
t2.equal(html, expectedHTML);

@@ -703,6 +703,6 @@ t2.end();

}),
'<select name="name" id="id_name" data-test="foo">' +
'<option value="val1">text1</option>' +
'<option value="val2">text2</option>' +
'</select>'
'<select name="name" id="id_name" data-test="foo">'
+ '<option value="val1">text1</option>'
+ '<option value="val2">text2</option>'
+ '</select>'
);

@@ -716,6 +716,6 @@ t.equal(

}),
'<select name="name" id="id_name" multiple="multiple" data-test="foo">' +
'<option value="val1">text1</option>' +
'<option value="val2">text2</option>' +
'</select>'
'<select name="name" id="id_name" multiple="multiple" data-test="foo">'
+ '<option value="val1">text1</option>'
+ '<option value="val2">text2</option>'
+ '</select>'
);

@@ -734,8 +734,8 @@

w.toHTML('name', field),
'<input type="checkbox" name="name" id="id_name_one" value="one" data-test="foo" />' +
'<label for="id_name_one">Item one</label>' +
'<input type="checkbox" name="name" id="id_name_two" value="two" checked="checked" data-test="foo" />' +
'<label for="id_name_two">Item two</label>' +
'<input type="checkbox" name="name" id="id_name_three" value="three" data-test="foo" />' +
'<label for="id_name_three">Item three</label>'
'<input type="checkbox" name="name" id="id_name_one" value="one" data-test="foo" />'
+ '<label for="id_name_one">Item one</label>'
+ '<input type="checkbox" name="name" id="id_name_two" value="two" checked="checked" data-test="foo" />'
+ '<label for="id_name_two">Item two</label>'
+ '<input type="checkbox" name="name" id="id_name_three" value="three" data-test="foo" />'
+ '<label for="id_name_three">Item three</label>'
);

@@ -754,8 +754,8 @@

w2.toHTML('name', field2),
'<input type="radio" name="name" id="id_name_one" value="one" data-test="foo" />' +
'<label for="id_name_one">Item one</label>' +
'<input type="radio" name="name" id="id_name_two" value="two" checked="checked" data-test="foo" />' +
'<label for="id_name_two">Item two</label>' +
'<input type="radio" name="name" id="id_name_three" value="three" data-test="foo" />' +
'<label for="id_name_three">Item three</label>'
'<input type="radio" name="name" id="id_name_one" value="one" data-test="foo" />'
+ '<label for="id_name_one">Item one</label>'
+ '<input type="radio" name="name" id="id_name_two" value="two" checked="checked" data-test="foo" />'
+ '<label for="id_name_two">Item two</label>'
+ '<input type="radio" name="name" id="id_name_three" value="three" data-test="foo" />'
+ '<label for="id_name_three">Item three</label>'
);

@@ -762,0 +762,0 @@

Sorry, the diff of this file is not supported yet

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