Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/model-patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@

var async = require('async');
var utils = require('prana').utils;
var validator = require('validator/lib/validators');

// Modify notEmpty validator method.
validator.notEmpty = function (data) {
if (typeof data === 'undefined' || data === null) return false;
if (typeof data === 'number' || typeof data === 'boolean') return true;
if (Object.prototype.toString.call(data) === '[object Function]')
if (typeof data.length !== 'undefined' && data.length === 0) return false;
if (typeof data === 'string' && data.match(/^[\s\t\r\n]*$/)) return false;
if (JSON.stringify(data) === '{}') return false;

return true;
};

var modelPatch = module.exports = {

Expand Down Expand Up @@ -171,7 +184,7 @@ var modelPatch = module.exports = {
var fieldFullName = (prefix ? prefix + ' - ' : '') + fieldSettings.title;

// If field is required check if a value was supplied for it.
if (fieldSettings.required && !(fieldName in item)) {
if (fieldSettings.required && !(fieldName in item && validator.notEmpty(item[fieldName]))) {
errors.push(fieldFullName + ' is required.');
return next(null, [fieldFullName + ' is required.']);
}
Expand Down