diff --git a/client/core/src/lib/validator.js b/client/core/src/lib/validator.js index 9f8d6d53f..e1a3dd1ed 100644 --- a/client/core/src/lib/validator.js +++ b/client/core/src/lib/validator.js @@ -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; diff --git a/services/loopback/common/models/client.js b/services/loopback/common/models/client.js index 2b21ccfa3..a6391e91e 100644 --- a/services/loopback/common/models/client.js +++ b/services/loopback/common/models/client.js @@ -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'); diff --git a/services/loopback/common/validations/validateDni.js b/services/loopback/common/validations/validateDni.js index c30890c6e..150603b7f 100644 --- a/services/loopback/common/validations/validateDni.js +++ b/services/loopback/common/validations/validateDni.js @@ -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();