diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig index 3ab047c494ad8..59380158448cb 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig @@ -32,7 +32,7 @@ {% block collection_widget %} {% spaceless %} {% if prototype is defined %} - {% set attr = attr|merge({'data-prototype': form_row(prototype) }) %} + {% set attr = attr|merge({'data-prototype': form_row(prototype), 'data-prototype-name': prototype.vars.name }) %} {% endif %} {{ block('form_widget') }} {% endspaceless %} diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php index 15e6530818b6a..b5e9b72267bbf 100644 --- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php @@ -1735,7 +1735,7 @@ public function testUrl() public function testCollectionPrototype() { $form = $this->factory->createNamedBuilder('name', 'form', array('items' => array('one', 'two', 'three'))) - ->add('items', 'collection', array('allow_add' => true)) + ->add('items', 'collection', array('allow_add' => true, 'prototype_name' => '__item__')) ->getForm() ->createView(); @@ -1746,6 +1746,14 @@ public function testCollectionPrototype() | //table[@id="name_items"][@data-prototype] +' + ); + + $this->assertMatchesXpath($html, + '//div[@id="name_items"][@data-prototype-name="__item__"] + | + //table[@id="name_items"][@data-prototype-name="__item__"] + ' ); }