jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
33.98k stars 2.79k forks source link

Multi Level Validation Errors and Warnings with Yup/Formik? #2870

Closed hatefk closed 4 years ago

hatefk commented 4 years ago

This is a long shot but Im wondering if there is a way to implement multi level validation warnings/errors via Yup and Formik?

For example lets say for value A possible values are 0-10. I want to implement the following validation schema:

"A > 10 or A< 0" --> Raise Error and do not let user submit "A > 8 or A< 2" --> Raise a Warning (Value is too high or too low) but let user submit "A > 6 or A< 4" --> Raise a Warning (Value is a little bit high ) but let user submit "A = 5" --> No error or message, just let the user submit.

maddhruv commented 4 years ago

There is nothing such as warning in formik. But what you can do to achieve this is by writing a custom validation function/schema to check for these conditions and show warning/error on the Input Field. While just adding the error conditions/validation to the formik form, which is A > 10 or A < 0 in your case

hatefk commented 4 years ago

Thanks @maddhruv