[Form] Fix for treatment zero as empty data. Closes #1986
This commit is contained in:
parent
12a852e18b
commit
c29fa9d64e
@ -655,7 +655,7 @@ class FormBuilder
|
|||||||
$instance->add($child);
|
$instance->add($child);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->getData()) {
|
if (null !== $this->getData()) {
|
||||||
$instance->setData($this->getData());
|
$instance->setData($this->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,6 +203,36 @@ class FieldTypeTest extends TypeTestCase
|
|||||||
$this->assertEquals(0, count($form->getAttribute('attr')));
|
$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
|
* @expectedException Symfony\Component\Form\Exception\FormException
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user