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 0.2.3 to 0.3.0

7

example/complex.js

@@ -70,3 +70,8 @@ /*jslint node: true */

}),
spam_me: fields.boolean()
spam_me: fields.boolean(),
nested_1: {
nested_2: {
nested: fields.string()
}
}
});

@@ -73,0 +78,0 @@

14

example/simple.js

@@ -28,10 +28,18 @@ /*jslint node: true */

}),
email: fields.email()
personal: {
name: fields.string({required: true, label: 'Name'}),
email: fields.email({required: true, label: 'Email'}),
address: {
address1: fields.string({required: true, label: 'Address 1'}),
address2: fields.string({label: 'Address 2'}),
city: fields.string({required: true, label: 'City'}),
state: fields.string({required: true, label: 'State'}),
zip: fields.number({required: true, label: 'ZIP'})
}
}
});
http.createServer(function (req, res) {
reg_form.handle(req, {
success: function (form) {
var req_data = require('url').parse(req.url, 1).query;
res.writeHead(200, {'Content-Type': 'text/html'});

@@ -38,0 +46,0 @@ res.write('<h1>Success!</h1>');

@@ -91,3 +91,2 @@ /*jslint node: true */

exports.number = function (opt) {

@@ -174,1 +173,5 @@ if (!opt) { opt = {}; }

exports.object = function (fields, opts) {
return forms.create(fields || {});
};

@@ -6,3 +6,3 @@ /*jslint node: true */

http = require('http'),
querystring = require('querystring'),
querystring = require('qs'),
parse = require('url').parse;

@@ -18,2 +18,6 @@

Object.keys(fields).forEach(function (k) {
// if it's not a field object, create an object field.
if (typeof fields[k].toHTML !== 'function' && typeof fields[k] === 'object') {
fields[k] = exports.fields.object(fields[k]);
}
fields[k].name = k;

@@ -34,3 +38,8 @@ });

}, {});
b.validate = function (callback) {
b.validate = function (obj, callback) {
if (arguments.length === 1) {
obj = callback;
callback = arguments[0];
}
async.forEach(Object.keys(b.fields), function (k, callback) {

@@ -58,3 +67,4 @@ b.fields[k].validate(b, function (err, bound_field) {

if (obj.method === 'GET') {
f.handle(parse(obj.url, 1).query, callbacks);
var qs = parse(obj.url).query;
f.handle(querystring.parse(qs), callbacks);
} else if (obj.method === 'POST' || obj.method === 'PUT') {

@@ -89,6 +99,13 @@ // If the app is using bodyDecoder for connect or express,

},
toHTML: function (iterator) {
toHTML: function (name, iterator) {
var form = this;
if (arguments.length === 1) {
name = iterator;
iterator = arguments[0];
}
return Object.keys(form.fields).reduce(function (html, k) {
return html + form.fields[k].toHTML(k, iterator);
var kname = typeof name === 'string' ? name + '[' + k + ']' : k;
return html + form.fields[k].toHTML(kname, iterator);
}, '');

@@ -95,0 +112,0 @@ }

@@ -12,3 +12,3 @@ /*jslint node: true */

trimEndRegexp = new RegExp(wsChars + wsChars + "*$"),
useES5 = function (str) { return String(str || '').trim(); };
useES5 = function (str) { return String(str || '').trim(); };
return String.prototype.trim && !ws.trim() ? useES5 : function (str) {

@@ -15,0 +15,0 @@ return String(str || '').replace(trimBeginRegexp, '').replace(trimEndRegexp, '');

@@ -79,3 +79,3 @@ /*jslint node: true */

value: w.formatValue(f.value)
}, userAttrs]);
}, userAttrs, w.attrs || {}]);
};

@@ -133,3 +133,3 @@ w.getDataRegExp = function () {

if (!f) { f = {}; }
return singleTag('input', {
return singleTag('input', [{
type: 'checkbox',

@@ -141,3 +141,3 @@ name: name,

value: 'on'
});
}, w.attrs || {}]);
};

@@ -161,7 +161,7 @@ return w;

}, '');
return tag('select', {
return tag('select', [{
name: name,
id: f.id || true,
classes: w.classes
}, optionsHTML);
}, w.attrs || {}], optionsHTML);
};

@@ -179,3 +179,3 @@ return w;

if (!f) { f = {}; }
return tag('textarea', {
return tag('textarea', [{
name: name,

@@ -186,3 +186,3 @@ id: f.id || true,

cols: opt.cols || null
}, f.value || '');
}, w.attrs || {}], f.value || '');
};

@@ -205,3 +205,3 @@ return w;

html += singleTag('input', {
html += singleTag('input', [{
type: 'checkbox',

@@ -213,3 +213,3 @@ name: name,

checked: !!checked
});
}, w.attrs || {}]);

@@ -231,7 +231,6 @@ // label element

w.toHTML = function (forID, f) {
var labelAttrs = {
return tag('label', [{
for: forID,
classes: w.classes
};
return tag('label', labelAttrs, opt.content);
}, w.attrs || {}], opt.content);
};

@@ -254,3 +253,3 @@ return w;

html += singleTag('input', {
html += singleTag('input', [{
type: 'radio',

@@ -262,3 +261,3 @@ name: name,

checked: !!checked
});
}, w.attrs || {}]);
// label element

@@ -288,3 +287,3 @@ html += tag('label', {for: id}, f.choices[k]);

}, '');
return tag('select', {
return tag('select', [{
multiple: true,

@@ -294,3 +293,3 @@ name: name,

classes: w.classes
}, optionsHTML);
}, w.attrs || {}], optionsHTML);
};

@@ -297,0 +296,0 @@ return w;

@@ -6,3 +6,3 @@ {

"author": "Caolan McMahon",
"version": "0.2.3",
"version": "0.3.0",
"repository": {

@@ -20,4 +20,11 @@ "type": "git",

"dependencies": {
"async": "~0.2.9"
"async": "~0.2.9",
"qs": "~0.6.5"
},
"devDependencies": {
"nodeunit": "~0.8.1",
"testling": "~1.5.1",
"browserify": "~2.29.0",
"nodeunit-browser-tap": "~0.0.3"
},
"licenses": [

@@ -47,10 +54,4 @@ {

]
},
"devDependencies": {
"nodeunit": "~0.8.1",
"testling": "~1.2.2",
"browserify": "~2.25.0",
"nodeunit-browser-tap": "~0.0.3"
}
}

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

[![Build Status][1]][2] [![dependency status][3]][4]
[![Build Status][1]][2] [![dependency status][3]][4] [![dev dependency status][5]][6]

@@ -345,2 +345,4 @@ # Forms

[4]: https://david-dm.org/caolan/forms
[5]: https://david-dm.org/caolan/forms/dev-status.png
[6]: https://david-dm.org/caolan/forms#info=devDependencies

@@ -309,1 +309,11 @@ /*jslint node: true */

exports['dynamic widget attributes'] = function(test) {
var re = /autocomplete="no"/;
Object.keys(forms.widgets).forEach(function(name) {
var w = forms.widgets[name]();
w.attrs = {autocomplete: 'no'};
var html = w.toHTML('test', {choices: {foo: 'bar'}});
test.equals(re.test(html), true);
});
test.done();
};
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