Browse Source

[Form] Add option "prototype" defaulting to true.

Benjamin Eberlei 14 years ago
parent
commit
d87651b6a2

+ 2 - 1
src/Symfony/Component/Form/Type/CollectionType.php

@@ -18,7 +18,7 @@ class CollectionType extends AbstractType
 {
     public function configure(FormBuilder $builder, array $options)
     {
-        if ($options['modifiable']) {
+        if ($options['modifiable'] && $options['prototype']) {
             $builder->add('$$name$$', $options['type'], array(
                 'property_path' => null,
                 'required' => false,
@@ -36,6 +36,7 @@ class CollectionType extends AbstractType
         return array(
             'template' => 'collection',
             'modifiable' => false,
+            'prototype'  => false,
             'type' => 'text',
         );
     }

+ 13 - 0
tests/Symfony/Tests/Component/Form/Type/CollectionTypeTest.php

@@ -54,6 +54,7 @@ class CollectionFormTest extends TestCase
         $form = $this->factory->create('collection', 'emails', array(
             'type' => 'field',
             'modifiable' => true,
+            'prototype' => true,
         ));
         $form->setData(array('foo@foo.com', 'foo@bar.com'));
 
@@ -83,6 +84,7 @@ class CollectionFormTest extends TestCase
         $form = $this->factory->create('collection', 'emails', array(
             'type' => 'field',
             'modifiable' => true,
+            'prototype' => true,
         ));
         $form->setData(array('foo@bar.com'));
 
@@ -148,6 +150,17 @@ class CollectionFormTest extends TestCase
         $this->assertEquals(array('foo@foo.com', 'bar@bar.com'), $form->getData());
     }
 
+    public function testModifableButNoPrototype()
+    {
+        $form = $this->factory->create('collection', 'emails', array(
+            'type' => 'field',
+            'modifiable' => true,
+            'prototype' => false,
+        ));
+
+        $this->assertFalse($form->has('$$name$$'));
+    }
+
     public function testResizedDownIfBoundWithLessDataAndModifiable()
     {
         $form = $this->factory->create('collection', 'emails', array(