Symfony2 multiple Entities of same class in one Form

前端 未结 2 2089
天涯浪人
天涯浪人 2021-01-15 00:37

I want to render a form which has multiple Entities of same Class. I will display 2 fields, Price(type=text) and Enabled(type=checkbox).

I don\'t know how many I wil

2条回答
  •  渐次进展
    2021-01-15 01:31

    I think you have missed a for loop in your twig file Check this example:

        {# store the prototype on the data-prototype attribute #}
        
      {% for emailField in form.emails %}
    • {{ form_errors(emailField) }} {{ form_widget(emailField) }}
    • {% endfor %}

    See the loop, I think that you need to add in your twig file.

    In addition to loops you need to add JavaScript also.

    Check this link:

    http://symfony.com/doc/current/reference/forms/types/collection.html#adding-and-removing-items

    Check the complete code. It will help you out to generate multiple entity forms from a single entity class using collection field type.

提交回复
热议问题