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.3 to 0.2.4

96

lib/form.js

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

/*eslint no-unused-vars: [2, {"vars": "all", "args": "none"}]*/
var util = require('util'),
express = require('express'),
EventEmitter = require('events').EventEmitter;

@@ -25,3 +27,3 @@

this.router = require('express').Router({ mergeParams: true });
this.router = express.Router({ mergeParams: true });
};

@@ -52,54 +54,55 @@

get: function (req, res, callback) {
var errors = this.getErrors(req, res);
this._getValues(req, res, function (err, values) {
if (err) {
return callback(err);
}
req.form = { values: values || {} };
debug('Rendering form for ' + req.path);
if (_.isEmpty(this.options.fields) && this.options.next) {
this.emit('complete', req, res);
}
_.extend(res.locals, {
errors: errors,
errorlist: _.map(errors, _.identity),
values: values,
options: this.options,
action: req.baseUrl !== '/' ? req.baseUrl + req.path : req.path
});
_.extend(res.locals, this.locals(req, res));
this.render(req, res, callback);
}.bind(this));
req.form = req.form || {};
var router = express.Router({ mergeParams: true });
router.use([
this._getErrors.bind(this),
this._getValues.bind(this),
this._locals.bind(this),
this.render.bind(this)
]);
router.use(function (err, req, res, next) {
callback(err);
});
if (_.isEmpty(this.options.fields) && this.options.next) {
this.emit('complete', req, res);
}
router.handle(req, res, callback);
},
post: function (req, res, callback) {
debug('Received POST for ' + req.path);
this.setErrors(null, req, res);
this._process(req, res, function (err) {
if (err) {
return callback(err);
}
this._validate(req, res, function (err) {
if (err) {
debug('Validation failed for ' + req.path);
debug(err);
callback(err);
} else {
debug('Validation passed for ' + req.path);
this.saveValues(req, res, function (err) {
if (err) {
callback(err);
} else {
this.successHandler(req, res);
}
}.bind(this));
}
}.bind(this));
}.bind(this));
req.form = req.form || {};
var router = express.Router({ mergeParams: true });
router.use([
this._process.bind(this),
this._validate.bind(this),
this.saveValues.bind(this),
this.successHandler.bind(this)
]);
router.use(function (err, req, res, next) {
callback(err);
});
router.handle(req, res, callback);
},
_locals: function (req, res, callback) {
_.extend(res.locals, {
errors: req.form.errors,
errorlist: _.map(req.form.errors, _.identity),
values: req.form.values,
options: this.options,
action: req.baseUrl !== '/' ? req.baseUrl + req.path : req.path
});
_.extend(res.locals, this.locals(req, res));
callback();
},
locals: function (/*req, res*/) {
return {};
},
render: function (req, res/*, callback*/) {
render: function (req, res, callback) {
res.render(this.options.template);
},
_getErrors: function (req, res, callback) {
req.form.errors = this.getErrors(req, res);
callback();
},
// placeholder methods for persisting error messages between POST and GET

@@ -151,3 +154,6 @@ getErrors: function (/*req, res*/) {

_getValues: function (req, res, callback) {
this.getValues(req, res, callback);
this.getValues(req, res, function (err, values) {
req.form.values = values || {};
callback(err);
});
},

@@ -154,0 +160,0 @@ getValues: function (req, res, callback) {

{
"name": "hmpo-form-controller",
"version": "0.2.3",
"version": "0.2.4",
"description": "",

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

@@ -190,3 +190,3 @@ var Form = require('../../');

form.render.should.have.been.calledOnce;
form.render.should.have.been.calledWithExactly(req, res, cb);
form.render.should.have.been.calledWith(req, res);
});

@@ -210,3 +210,3 @@

cb.should.have.been.calledOnce;
cb.should.have.been.calledWithExactly({ error: 'message' });
cb.should.have.been.calledWith({ error: 'message' });
});

@@ -213,0 +213,0 @@

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