Collection Fields are unable to persist correctly on "Add new" action
tl;dr: Collection forms do not start to count from N (where N is the amount of toMany-items are existing), but always from 0. Meaning that after the initial creation of entities trough for example Crud::NEW, its not possible anymore to add new elements in the expected way.
Example code:
yield FormField::addTab(t('Bank accounts'), 'fas fa-university');
yield CollectionField::new('bank_accounts', t('Bank accounts'))
->useEntryCrudForm(BankAccountCrudController::class)
->hideOnIndex()
->setColumns('col-sm-12 col-md-6');
Now, create the entity and save it once. Now, go ahead and attempt to add a new entity trough this collection, and it will give the new spawned fields the ID 0, which is already taken by the previously generated Bank account, or whatsoever.
Now, you will override the actual key 0 with the "new" one, but if you add two new ones and only fill the second form, you will end up losing both again. :-)
So its not more than a number bug somewhere, I haven't found it yet. This happens in v4.15.4.
This issue has been inactive for 3 months. It will be closed in 5 days unless there is new activity.
Check if this is still relevant (maybe it was already fixed by some PR) and leave a comment or update the issue with any new information.
Thanks for reporting this.
We are closing this issue because it has had no activity for the last 3 months. This helps us keep the tracker manageable and focus on actively discussed work.
If this is still relevant, please reopen the issue (or open a new one) with updated information, and any logs or stack traces you can share.