form.js
* @module greppy/helper/controller/form
* @author Hermann Mayer <hermann.mayer92@gmail.com>
* Remap a scalar value into an array.
* @param {Mixed} list - Value or list to remap to array
Form.prototype.sanitizeList = function(list)
if (list && !(list instanceof Array)) {
* Log and flash the error messsages.
* @param {Object} req - Client request
* @param {Object} err - Error Object
Form.prototype.logAndFlash = function(req, err)
var message = 'Validation error occured at ' +
req.url.green.bold + ' - Details: ';
message += '\n' + JSON.stringify(err, null, 4);
message += 'No details given';
if (err.hasOwnProperty('name') && 'ValidationError' == err.name) {
Object.keys(err.errors).forEach(function(key) {
req.flash('error', err.errors[key].message);
// Default case - normal error instance
return req.flash('error', err.message);
// Given error is an array - looks like Sequelize
Object.keys(err).forEach(function(key) {
if ('function' !== err[key].forEach) {
err[key].forEach(function(error) {
* Remap a scalar value into an array containing a single
* integer or convert an array into array containing
* @param {Mixed} list - Value or list to remap
Form.prototype.sanitizeIntegerList = function(list)
if (list && !(list instanceof Array)) {
list = list.map(function(item) {
* Remap a scalar value into an array containing a single
* string or convert an array into array containing
* @param {Mixed} list - Value or list to remap
Form.prototype.sanitizeStringList = function(list)
if (list && !(list instanceof Array)) {
list.forEach(function(itm, idx) {
* Remap a scalar value into an array containing a single
* float or convert an array into array containing
* @param {Mixed} list - Value or list to remap
Form.prototype.sanitizeFloatList = function(list)
if (list && !(list instanceof Array)) {