Permalink
Browse files

ResizeDataListener::presetData and ::preBind should should pass data …

…when recreating rows
  • Loading branch information...
1 parent 774ac80 commit ffa26754fec590887e63e941016644a460c34070 @asm89 committed Sep 20, 2011
View
4 src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php
@@ -90,7 +90,7 @@ public function preSetData(DataEvent $event)
// Then add all rows again in the correct order
foreach ($data as $name => $value) {
- $form->add($this->factory->createNamed($this->type, $name, null, array_replace(array(
+ $form->add($this->factory->createNamed($this->type, $name, $value, array_replace(array(
'property_path' => '['.$name.']',
), $this->options)));
}
@@ -122,7 +122,7 @@ public function preBind(DataEvent $event)
if ($this->allowAdd) {
foreach ($data as $name => $value) {
if (!$form->has($name)) {
- $form->add($this->factory->createNamed($this->type, $name, null, array_replace(array(
+ $form->add($this->factory->createNamed($this->type, $name, $value, array_replace(array(
'property_path' => '['.$name.']',
), $this->options)));
}
View
10 tests/Symfony/Tests/Component/Form/Extension/Core/EventListener/ResizeFormListenerTest.php
@@ -58,14 +58,14 @@ public function testPreSetDataResizesForm()
$this->factory->expects($this->at(0))
->method('createNamed')
- ->with('text', 1, null, array('property_path' => '[1]', 'max_length' => 10))
+ ->with('text', 1, 'string1', array('property_path' => '[1]', 'max_length' => 10))
->will($this->returnValue($this->getForm('1')));
$this->factory->expects($this->at(1))
->method('createNamed')
- ->with('text', 2, null, array('property_path' => '[2]', 'max_length' => 10))
+ ->with('text', 2, 'string2', array('property_path' => '[2]', 'max_length' => 10))
->will($this->returnValue($this->getForm('2')));
- $data = array(1 => 'string', 2 => 'string');
+ $data = array(1 => 'string1', 2 => 'string2');
$event = new DataEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array('max_length' => '10'), false, false);
$listener->preSetData($event);
@@ -102,10 +102,10 @@ public function testPreBindResizesUpIfAllowAdd()
$this->factory->expects($this->once())
->method('createNamed')
- ->with('text', 1, null, array('property_path' => '[1]', 'max_length' => 10))
+ ->with('text', 1, 'string2', array('property_path' => '[1]', 'max_length' => 10))
->will($this->returnValue($this->getForm('1')));
- $data = array(0 => 'string', 1 => 'string');
+ $data = array(0 => 'string1', 1 => 'string2');
$event = new DataEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array('max_length' => 10), true, false);
$listener->preBind($event);

0 comments on commit ffa2675

Please sign in to comment.