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.
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.