[Form] Let null values to unset fields in PATCH requests
This commit is contained in:
parent
b85b78f24a
commit
f5812c5e40
|
@ -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]);
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
Reference in New Issue