Bug with empty value validations fixed

This commit is contained in:
Juan 2018-02-27 22:50:14 +01:00
parent 4eebdf96ee
commit 8ee649b9d0
3 changed files with 10 additions and 6 deletions

View File

@ -72,9 +72,11 @@ export function validateAll(value, validations) {
export function validate(value, conf) {
let validator = validators[conf.validation];
try {
checkNull(value, conf);
let isEmpty = value == null || value === '';
if (validator) // && value != null ??
if (isEmpty)
checkNull(value, conf);
if (validator && (!isEmpty || conf.validation == 'presence'))
validator(value, conf);
} catch (e) {
let message = conf.message ? conf.message : e.message;

View File

@ -43,7 +43,9 @@ module.exports = function(Self) {
var validateIban = require('../validations/validateIban');
Self.validateBinded('iban', validateIban, {
message: 'El iban no tiene el formato correcto'
message: 'El iban no tiene el formato correcto',
allowNull: true, // FIXME: Ignored by loopback when it's false
allowBlank: true
});
let validateDni = require('../validations/validateDni');

View File

@ -1,6 +1,6 @@
module.exports = fiWithCountry => {
if (fiWithCountry == null)
return true;
module.exports = function(fiWithCountry) {
if (fiWithCountry == null) return true;
if (typeof fiWithCountry != 'string') return false;
fiWithCountry = fiWithCountry.toUpperCase();