[Form] Let null values to unset fields in PATCH requests

This commit is contained in:
Alessandro Tagliapietra 2013-09-27 13:47:53 +02:00
parent b85b78f24a
commit f5812c5e40
2 changed files with 14 additions and 1 deletions

View File

@ -548,7 +548,7 @@ class Form implements \IteratorAggregate, FormInterface
}
foreach ($this->children as $name => $child) {
if (isset($submittedData[$name]) || $clearMissing) {
if (array_key_exists($name, $submittedData) || $clearMissing) {
$child->submit(isset($submittedData[$name]) ? $submittedData[$name] : null, $clearMissing);
unset($submittedData[$name]);
}

View File

@ -82,6 +82,19 @@ class CompoundFormTest extends AbstractFormTest
$this->assertTrue($form->isValid());
}
public function testSubmitForwardsNullIfNotClearMissingButValueIsExplicitlyNull()
{
$child = $this->getMockForm('firstName');
$this->form->add($child);
$child->expects($this->once())
->method('submit')
->with($this->equalTo(null));
$this->form->submit(array('firstName' => null), false);
}
public function testSubmitForwardsNullIfValueIsMissing()
{
$child = $this->getMockForm('firstName');