Usage of the Collection field type allows users to only select one entity and it is not possible to select multiple. To achieve multiple selection I’m required to use dropdown with manual search queries (that’s fine).
Requested feature from my client was - to be able to select an entity (via collection or dropdown) and then this entity will create new field/set of fields in the form to manipulate it
e.g. When form opens I do have 2 fields (Collection, Checkbox), that have label Entity #1 and EntityCheckbox #1. Then select an entity via Collection field and when this field is selected, I would like to adjust the form to add new set of fields below first set, with names Entity #2, EntityCheckbox #2. I have tried to do this via pushing this items to a form array, replacing the form array with new, generating it via a function.
Is it possible to add new fields to the from on the fly? Or I need to pre-populate it with some amount of fields and just show them with a condition (not a solution for me)?
I suppose this is a follow up to the previous discussion we had about dynamic forms.
I tried to implement something in the way you have described, it is rudimentary but it seems to work fine.
Adding and removing elements from the list updates the form as expected:
It did the trick for me, thanks. Weird that i have tried to do almost the same, but instead of checking the values of the array, I relied on existing objects in the form array.
Btw, thank you again!