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

Remove empty item?

Open mmahalwy opened this issue 7 years ago • 6 comments

Field component has the parse prop that allows authors to change the value before storage. That being said, FieldArray does not have the same prop and makes it difficult to parse out empty items. This will need to be done after submitting which is not ideal.

Thoughts or ideas?

mmahalwy avatar May 01 '18 00:05 mmahalwy

Can you describe your use case further? If an array field becomes empty, i.e. '', it should be removed from the array?

erikras avatar May 01 '18 18:05 erikras

@erikras that's correct. If, for whatever reason, the user adds another input but does not add any content, the array will be ['Something new', 'another thing', '']. Ideally, we can parse out the empty string element.

See: image

mmahalwy avatar May 01 '18 19:05 mmahalwy

What does your code look like? Are you doing whatToBringArray.map in the render method? If so, you could do whatToBringArray.filter(...).map and also onsubmit you can filter the empty ones out

wespickett avatar May 04 '18 01:05 wespickett

@wespickett when we map through the array of fields we need to show empty results in order to give ability to a user to fill an input.

@erikras +1 I'd like to have simpler and accurate solution rather then filter empty results in submit handler. It would be great to encapsulate array-related logic inside an array-fields component and have ability to parse the result before it reaches the submit handler. But at the same time it should be visible as empty on UI for the user.

likerRr avatar Jul 16 '19 13:07 likerRr

I'm currently building a mechanism to always ensure there's an empty final element in the array (to render an empty text area without the need for an "add" button). This request would make such a requirement trivial.

mhuxtable avatar Jul 28 '19 14:07 mhuxtable

I like this library. I'm running into the same issue. Any updates?

tonymaibox avatar Apr 29 '20 18:04 tonymaibox