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] Nested FieldArrays and setTouched not working together

See original GitHub issue

Bug, Feature, or Question?

Bug

Current Behavior

When you have nested FieldArrays, let’s say the following path: questions.0.values.0.label where questions and values are the arrays and label is a regular input field. When onBlur is invoked on label, it wants to touch the path. But at that point (due to changing the values array) the current touched state is:

questions: 0: {form_question_type_id: true, values: true}

which causes the following error in setDeep:

Uncaught TypeError: Cannot create property '0' on boolean 'true'

which happens on the last line of this method: https://github.com/jaredpalmer/formik/blob/next/src/utils.ts#L69

Desired Behavior

It should update the touched state to a deep nested state like this:

questions: 0: {form_question_type_id: true, values: { label: true }}

Suggested Solutions

I’m not sure I understand the current implementation of setDeep. Why not just clone the object and use something like https://github.com/kalmbach/bury?

Info

  • Formik Version: 0.11.0-beta.1
  • OS: Mac OS High Sierra
  • Node Version: v9.4.0
  • Package Manager and version: Yarn v1.3.2

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:22 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
arvinsimcommented, Sep 24, 2020

@elvisguillen So is your structure an array of array items? Trying to understand why you put value[0].

@jaredpalmer Is the documentation updated? Trying to find out how touched is being handled for an array of objects.

2reactions
timc13commented, Jan 26, 2018

why not stick with lodash and use set which works for bracket notation AND dot notation…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Arrays and Nested Objects - Formik
Formik has support for nested objects and arrays out of the box. ... This means that you do not need to flatten out...
Read more >
How to dynamically access nested errors/touched on formik ...
Now I am experimenting with formik (with Yup validation) and have run into a problem dynamically accessing the error and touched fields when ......
Read more >
How to use Formik - Appliz
Disabling submit · run the validation on page load: use the validateOnMount prop on the top Formik component. · update disabilty rule of...
Read more >
Nested Objects and Arrays - VeeValidate
Field arrays are a special type of nested array fields, they are often used to collect repeatable pieces of data or repeatable forms....
Read more >
useForm - setValue - React Hook Form
It will not create a new field when targeting a non-existing field. ... doesn't create new input setValue('test.101.data') // ✓ work on refresh...
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