E
E
eifory2021-01-04 12:38:31
Node.js
eifory, 2021-01-04 12:38:31

How to return an object as a result of validation?

For validation, validatejs is used.
When writing my own
validate.validators.myValidator = ......
I can return both a string and an object, but if the validator is written as a function inside constraints,
I can't.

const constraints = {
  link: function (value, attributes, attributeName, options, globalOptions) {
    return {
        error: 'x',
        code: 'y'
    };
  }
};

const links = {
  link: 'z'
}

validate(links, constraints)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question