Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yup validations does not stop if one validation rule fails #2225

Open
AkshayGadekar opened this issue Jun 28, 2024 · 0 comments
Open

Yup validations does not stop if one validation rule fails #2225

AkshayGadekar opened this issue Jun 28, 2024 · 0 comments

Comments

@AkshayGadekar
Copy link

AkshayGadekar commented Jun 28, 2024

const schema = Yup.object().shape({
        email: Yup.string().required().email().matches(/@.+\..+/, 'email must be a valid email').test('email-exists', 'email already exists', (value) => {
            // api which checks if email exits in database
            console.log('api triggered')
            return false // assume email exists
        })
    })
await schema.validate({ email: 'a' }, { abortEarly: false })

here we get three error messages, at test() api gets hit unnecessarily. what I want if email() rule is failed, yup should stop validating next rules. I wish if we could have abortEarly: true on field itself, not on validate function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant