question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

get all validation errors

See original GitHub issue

hi,

I just switched from joi to yup, and was wondering if there was a way to get all the validation errors – not only the first one.

var yup = require('yup');

var schema = yup.object().shape({
    age: yup.number().required(),
    name: yup.string().required()
});

schema.validate({})
    .catch(function(e) {
        console.log(e);
    });

only complains about age being required. whereas joi’s result.error.details gives me all the errors:

const result = joi.validate({}, schema);
result.error.details
    .forEach(function(detail) {
        // ...
    });

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

100reactions
jquensecommented, Apr 26, 2016

its not super visible but you can pass in an abortEarly: false as an option to validate to get all the errors;

https://github.com/jquense/yup#mixedvalidatevalue-any-options-object-callback-function-promiseany-validationerror

81reactions
shibbircommented, Jan 17, 2021
const yup = require('yup');

const schema = yup.object().shape({
    age: yup.number().required('This is required.'),
    name: yup.string().required('This is required.')
});

schema.validate(data, { abortEarly: false }).then(function() {
    // Success
}).catch(function (err) {
    err.inner.forEach(e => {
        console.log(e.message, e.path));
    });
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Get all validation errors from Angular 2 FormGroup
Recursive way to retrieve all the errors from an Angular form, after creating any kind of formulary structure there's no way ...
Read more >
Get all validation errors for Angular FormGroup - gists · GitHub
Get all validation errors for Angular FormGroup. GitHub Gist: instantly share code, notes, and snippets.
Read more >
Angular — Display every validation errors for your form
If you want to show errors for only a single FormControl, then you can just use Angular's JsonPipe that converts a value into...
Read more >
Show Validation Error Messages for Reactive Forms in ...
In this example, I'll define a reactive form with one text field. We'll configure this field to have a few validation rules before...
Read more >
How to Display Validation or Error Messages in Angular Forms
You'll create a form with a single input to get an understanding of Angular forms. First, you must include reactive forms in app.module.ts....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found