ansman/validate.js

Value not passed to custom validator if nested validation

Opened this issue · 0 comments

Custom validator:

_customValidator() {
       validate.validators.custom = function (value, options, key, attributes) {
           console.log(sprintf("Custom validation %s value: %s", key, value));
           console.log("Custom validation %s options: %s",key, options);
           console.log("Custom validation %s attributes: %s", key, JSON.stringify(attributes));

           return "is totally wrong";
       };
   },

Console Log:
// Value passed correctly for single level validation
Custom validation lastname value: Flintstone
Custom validation lastname options: true
Custom validation lastname attributes: {"firstname":"","lastname":"Flintstone","":{},"names":[{"firstname":"Barney","lastname":"Rubble"},{"firstname":"Wilma","lastname":"Flintstone"}]}

// Value undefined for nested validation
Custom validation names.lastname value: undefined
Custom validation names.lastname options: true
Custom validation lastname attributes: {"firstname":"","lastname":"Flintstone","":{},"names":[{"firstname":"Barney","lastname":"Rubble"},{"firstname":"Wilma","lastname":"Flintstone"}]}