Skip to content
Advertisement

empty elements in symfony form collection

I have a simple form with collection of items in it. Just like described here: http://symfony.com/doc/current/cookbook/form/form_collections.html.

The problem is when I add new element (or multiple elements) WITHOUT touching enything in them (not changing theirs inputs) I get an empty collection.

I would like to get a collection of added elements regardless theirs content. And even if there are fields are empty it would be ok.

In my case after form submission I have:

JavaScript

On the other hand if somethig is set then it is ok:

JavaScript

Any ideas how to get rid of that bug?


UPDATED

Partner’s class mapping is:

JavaScript

field partners is added to the form of Step2 entity like collection with allow_add, allow_delete, by_reference set to false

Advertisement

Answer

ok, I found a problem.

I must to set empty_data in subform (Partner class).


I don’t understand why but when all fields of related class (Partners) are submitted to be "" (empty) then in method sumbit of class SymfonyComponentFormForm the block

JavaScript

gives null in $viewData for Partner of empty fields. For object submitted to be the Partner with at least one field not empty $viewData is needed object.


All that is because

JavaScript

for empty object is Closure which eventually results to null, but for Partner with at least one field not empty it gives directly needed object.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement