[Next] What's the best way to handle FieldArray validation?
See original GitHub issueBug, Feature, or Question?
Question
Info
Since you need to have no errors on the array does this make the most sense for validating Arrays or am I making this too difficult? If you don’t return undefined for the array, the submit will not work.
products is an array with each object having a name, cases, and bottles.
export const validate = values => {
const errors = {};
if (!values.customer) errors.customer = 'Required';
if (!values.date) errors.date = 'Required';
const productErrors = [];
values.products.forEach(product => {
let errors = {};
if (!product.name) errors.name = 'Required';
if (!product.cases && !product.bottles) {
errors.cases = 'Required';
errors.bottles = 'Required';
}
productErrors.push(errors);
});
if (productErrors.some(errorObject => !isEmpty(errorObject))) {
errors.product = productErrors;
} else {
errors.product = undefined;
}
return errors;
};
- Formik Version: 0.11.0-rc2
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
<FieldArray /> | Formik
For convenience, calling these methods will trigger validation and also manage touched for you. Copy. 1 import React from 'react';. 2 import {...
Read more >React FieldArray Form Tutorial: Using Formik, Yup ... - YouTube
In this tutorial, we'll build a donations platform using the Formik FieldArray form with React and Yup for validation.In order to validate ......
Read more >Validating FieldArrays in Redux Form - Illuminated Computing
For each field it iterates over its validators and reports the first error it finds. It's simple, but it doesn't know how to...
Read more >Formik FieldArray Validation not Validating - Stack Overflow
So in my experience it allows you to submit the form because its you don't have an initial value, unless you are to...
Read more >useFieldArray - Simple React forms validation
control object provided by useForm . It's optional if you are using FormContext. shouldUnregister, boolean. Whether Field Array will be unregistered after ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Check out the latest version.
I have the same problem, I can not set the fieldarray as touched, setFieldTouched creates as object and not as array. And when I push he also does not arrow as touched.