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.