diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index b67700a6f3..8a19f82a2d 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -873,6 +873,10 @@ class Form implements \IteratorAggregate, FormInterface // Never initialize child forms automatically $options['auto_initialize'] = false; + if (null === $type && null === $this->config->getDataClass()) { + $type = 'text'; + } + if (null === $type) { $child = $this->config->getFormFactory()->createForProperty($this->config->getDataClass(), $child, null, $options); } else { diff --git a/src/Symfony/Component/Form/Tests/CompoundFormTest.php b/src/Symfony/Component/Form/Tests/CompoundFormTest.php index b5440ccbee..5ebb9906fa 100644 --- a/src/Symfony/Component/Form/Tests/CompoundFormTest.php +++ b/src/Symfony/Component/Form/Tests/CompoundFormTest.php @@ -207,6 +207,22 @@ class CompoundFormTest extends AbstractFormTest $this->assertSame(array(0 => $child), $this->form->all()); } + public function testAddWithoutType() + { + $child = $this->getBuilder('foo')->getForm(); + + $this->factory->expects($this->once()) + ->method('createNamed') + ->with('foo', 'text') + ->will($this->returnValue($child)); + + $this->form->add('foo'); + + $this->assertTrue($this->form->has('foo')); + $this->assertSame($this->form, $child->getParent()); + $this->assertSame(array('foo' => $child), $this->form->all()); + } + public function testAddUsingNameButNoType() { $this->form = $this->getBuilder('name', null, '\stdClass')