Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation of remove and removeBatch #98

Open
dunja-v opened this issue Sep 19, 2023 · 0 comments
Open

Documentation of remove and removeBatch #98

dunja-v opened this issue Sep 19, 2023 · 0 comments

Comments

@dunja-v
Copy link

dunja-v commented Sep 19, 2023

Are you submitting a bug report or a feature request?

Documentation update request - I'm not sure if that counts as a bug or a feature.

What is the current behavior?

The current documentation for remove and removeBatch methods:

form.mutators.remove
(name: string, index: number) => any

Removes a value from the specified index of the field array. Returns the removed value.

form.mutators.removeBatch
(name: string, indexes: Array<number>) => void

Removes the values at the specified indexes of the field array.

What is the expected behavior?

The documentation above didn't prepare me for the fact that, if there's only one value left in the field array, the result won't be an empty array. If the last element is removed from the array, the whole array gets removed and the field is set to undefined.

Sandbox Link

What's your environment?

Other information

Code that sets the array to undefined if its length is zero: https://github.com/final-form/final-form-arrays/blob/fe3c260939cbdd446a48304dd2df0be2a1c41237/src/remove.js#L20C5-L22C18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant