1
votes

I have two questions related to Yup validation library... Those questions are connected to each other.

First Question.

Is there any way how I can enable validation that will return all errors from validation. Look at example:

  const petSchema = yup.string().min( 5 ).oneOf( [ 'cat', 'dog' ] );

  petSchema.validate( 'ox', { abortEarly: false } ).catch( ( e ) => {
    console.log( e );
  } );

I expect that I will receive error message from min and oneOf but instead I just receiving one error: this must be one of the following values: cat, dog. This is silly example but I have password form with different validation rules and I want to display those rules all at one to the user. I think I can find other use cases for it... I think abortEarly should work but it just not works as expected.

Second question:

Let's assume I have email field and I want to check it on frontend side with string().required().email() schema and one more check in backend using async custom test method.

Problem is that when required or email fails my async test is also called. Is there any way how I can stop calling async test if previous sync validators fails? Also this is related to first question because it does not make any sense if I can only display one error and it generates not required traffic on server.

1

1 Answers

1
votes

EDIT: About your validation, it seems to me that simply oneOf and min are not compatible, and it make sense to me (if you're checking an enum, why should you check the length?). Testing with min and max you get correctly two ValidationError from err.inner, as you can see in this StackBlitz project

About the multiple fields validation, in this case there is still a message, but if you console.log the error object you'll see an errors property, which is an array with all the detailed errors.

About the sequential validation, unfortunately this is still not supported as tracked on project issue: https://github.com/jquense/yup/issues/851