question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Next] What's the best way to handle FieldArray validation?

See original GitHub issue

Bug, 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:closed
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
jaredpalmercommented, Feb 1, 2018

Check out the latest version.

0reactions
marcosjuniorzupcommented, Apr 15, 2019

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.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found