Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Form] Fix for treatment zero as empty data. Closes #1986
  • Loading branch information
stloyd committed Aug 22, 2011
1 parent 12a852e commit c29fa9d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/FormBuilder.php
Expand Up @@ -655,7 +655,7 @@ public function getForm()
$instance->add($child);
}

if ($this->getData()) {
if (null !== $this->getData()) {
$instance->setData($this->getData());
}

Expand Down
Expand Up @@ -203,6 +203,36 @@ public function testGetAttributesIsEmpty()
$this->assertEquals(0, count($form->getAttribute('attr')));
}

/**
* @see https://github.com/symfony/symfony/issues/1986
*/
public function testSetDataThroughParamsWithZero()
{
$form = $this->factory->create('field', null, array('data' => 0));
$view = $form->createView();

$this->assertFalse($form->isEmpty());

$this->assertSame('0', $view->get('value'));
$this->assertSame('0', $form->getData());

$form = $this->factory->create('field', null, array('data' => '0'));
$view = $form->createView();

$this->assertFalse($form->isEmpty());

$this->assertSame('0', $view->get('value'));
$this->assertSame('0', $form->getData());

$form = $this->factory->create('field', null, array('data' => '00000'));
$view = $form->createView();

$this->assertFalse($form->isEmpty());

$this->assertSame('00000', $view->get('value'));
$this->assertSame('00000', $form->getData());
}

/**
* @expectedException Symfony\Component\Form\Exception\FormException
*/
Expand Down

0 comments on commit c29fa9d

Please sign in to comment.