Skip to content

[Cookbook][Form] jquery code for adding collection element #1382

Closed
@Venzon

Description

@Venzon

http://symfony.com/doc/master/cookbook/form/form_collections.html#allowing-new-tags-with-the-prototype

I noticed that there can be some issue in example of jquery code for adding new colletion element from prototype.
In case when some elements will be removed and then some added we can get situation when some collection forms will get placeholder name replaced with number which already exists in list.

Imho instead of using collectionHolder.children().length there should be some unique value for each new added collection element (maybe incremented variable) - collectionHolder.children().length will not always return unique number not used in form collection html.

Easiest way to reproduce problematic situation is to remove some elements from the middle of collection and then add new elements... you can notice that indexes will be duplicated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions