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.

Nested Fields can cause issues (FieldArray > Field > Field)

See original GitHub issue

Are you submitting a bug report or a feature request?

I think it could be a bug, but perhaps I am doing something that is not intended.

What is the current behavior?

I have a scenario where I have a FieldArray with a Field, that has a Field as child. The idea is that we only show the maxLength field if the parent isList field is true. Sorry, for the sudo-code here, but this is an example of the nesting:

<FieldArray name="options">
{({ fields }) => {
	{fields.map((name, index) => (
		<div>
			<Field name={`${name}.title`} component="Input" />
			<Field name={`${name}.isList`} type="checkbox"}>
				{({input, meta}) => (
					<div>
						{input.isList ? (
							<Field name={`${name}.maxLength`} component="Input />
						)
						: (<div>foo</div>)
							
						}
					</div>
				)}
			</Field>
		</div>
	)}
}
</FieldArray>

The fields all work fine this way, however when using move as provided from the FieldArray’s fields property, it results in an error:

fields.move(0, 1)
_react_final_form_-_field_arrays_-_codesandbox

What is the expected behavior?

Fields would move, and the form would not explode.

Sandbox Link

At the default state, click the massively oversized “Move” button.

https://codesandbox.io/s/32p402x3om

What’s your environment?

"final-form": "4.10.0",
"final-form-arrays": "1.1.0",
"react": "16.4.0",
"react-dom": "16.4.0",
"react-final-form": "3.6.5",
"react-final-form-arrays": "1.0.6",
"styled-components": "3.3.2"

Other information

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
311chaoscommented, Aug 31, 2018

Thanks @lukeschunk . I could edit it, but I guess I will leave it to forever memorialize my mistake.

3reactions
jwldcommented, Sep 5, 2019

Please fix this…it’s killing me slowly…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nested fieldarray in formik - Stack Overflow
You problem is in how you pass the name for the component: name={`${itineraries[index].itinerary[idx]}.overnight`}.
Read more >
Object Fields VS. Nested Field Types in Elasticsearch - Opster
Too many nested objects could cause performance degradation or mapping explosion. Use flattened field type to map all keyword fields of an inner...
Read more >
useFieldArray - Simple React forms validation
Custom hook for working with Field Arrays (dynamic form). ... for nested field array, you will have to cast the field array by...
Read more >
Working with nested data - Splunk Documentation
Extract and promote a nested field to a top-level field. ... Flattening fields with such nested data can make extracting data easier.
Read more >
Field Names - Final Form Docs
Field names are strings that allow dot-and-bracket syntax, allowing you to create arbitrarily deeply nested fields. There are four main things you need...
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