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

QUESTION - Get required fields #1051

Closed
maximilianoforlenza opened this issue Sep 29, 2020 · 2 comments
Closed

QUESTION - Get required fields #1051

maximilianoforlenza opened this issue Sep 29, 2020 · 2 comments

Comments

@maximilianoforlenza
Copy link

maximilianoforlenza commented Sep 29, 2020

Hi everyone! I'd need to get the required fields to make some validations.
I've seen this issue in formik jaredpalmer/formik#1241, and this solution jaredpalmer/formik#1241 (comment) works when the validation doesn't use when, in this case tests is an empty array.

This is my schema:

Yup.object().shape({
    response: Yup.number().required(messages.REQUIRED_FIELD),
    noResponseReason: Yup.number().when('response', {
        is: 2,
        then: Yup.number().required(messages.REQUIRED_FIELD),
        otherwise: Yup.number()
    })
})

Could anyone help me? Thanks!

@maximilianoforlenza maximilianoforlenza changed the title Get required fields QUESTION - Get required fields Sep 29, 2020
@maximilianoforlenza
Copy link
Author

FYI I fixed that using Yup.lazy

@UnderTheMoonspell
Copy link

@maximilianoforlenza ive seen tons of questions with this same issue, but haven't seen a solution, could you give an example on how you did it?

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

2 participants