react-final-form icon indicating copy to clipboard operation
react-final-form copied to clipboard

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

Open 311chaos opened this issue 8 years ago • 6 comments

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

311chaos avatar Aug 31 '18 20:08 311chaos

*pseudo-code

lukeschunk avatar Aug 31 '18 22:08 lukeschunk

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

311chaos avatar Aug 31 '18 23:08 311chaos

sudo code

You sound like my boss! 🤣 ❤️

sandwich

erikras avatar Sep 03 '18 20:09 erikras

I have been trying to find work arounds for this issue, and have discovered some additional issues. It seems the latest updates to final-form-arrays or react-final-form-arrays have made the issue worse.

An example of move NOT working in the most basic way while using the latest lib versions:

https://codesandbox.io/s/jz63zn3mkv

If you downgrade that same code (as taken from the example in the repo) to older versions of final-form, it starts to work again:

https://codesandbox.io/s/33r815996

311chaos avatar Sep 07 '18 22:09 311chaos

The problem with this is the unmount from react-final-form still reference to old field names even when the index changes. However final form should handle deletion of validators in a more graceful manner inside unsubscription and not completely failed

Juansasa avatar May 10 '19 07:05 Juansasa

Please fix this...it's killing me slowly...

jwld avatar Sep 05 '19 15:09 jwld