Formik and Yup array validation #3607
Unanswered
miloszsobczak
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Following question and potential conversation is the result of this formik sample code.
Let's imagine the Yup schema consists of typed array, both with some validation rules for array and its nested type.
Let's assume that both have some errors - to many objects, and too short string values at least in one of them.
The
errors
response we get is bidirectional, so we get either the array or the type one.and
There are a few problems with this approach.
Usually we build some generic components on top of Field formik component to be consumable by different contexts, different pages. The component should contain validation conditions and proper styling. For this case we could use
getFieldMeta
to extract the errors and some other helpful indicators for this particular field. The problem is thatgetFieldMeta
refers to the same name field (array one -> [people]), not the indexable one ([people.n)).That being said a current implementation causes a ton of fleaky conditions to properly handle such a mechanism.
--
I'd see a least 2 solutions to this problem.
getFieldMeta
) should cover the nested, separate validations.What do you think? Am I misunderstanding something or the reality is as I've described here?
Beta Was this translation helpful? Give feedback.
All reactions