jquense / yup

Dead simple Object schema validation
MIT License
22.72k stars 925 forks source link

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

Open AkshayGadekar opened 2 months ago

AkshayGadekar commented 2 months ago
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.