8000 updated fix · symfony/symfony@f2c8a6f · GitHub
[go: up one dir, main page]

Skip to content

Commit f2c8a6f

Browse files
committed
updated fix
1 parent fa45a70 commit f2c8a6f

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

src/Symfony/Component/Form/Extension/Core/Type/CheckboxType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function configureOptions(OptionsResolver $resolver)
5959
'value' => '1',
6060
'empty_data' => $emptyData,
6161
'compound' => false,
62+
'clear_missing' => true, // internal
6263
));
6364
}
6465

src/Symfony/Component/Form/Form.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,9 @@ public function submit($submittedData, $clearMissing = true)
562562

563563
foreach ($this->children as $name => $child) {
564564
$isSubmitted = array_key_exists($name, $submittedData);
565-
$clearMissing = $this->getConfig()->getOption('expanded') ?: $clearMissing;
565+
// Some form types like {@link \Symfony\Component\Form\Extension\Core\Type\CheckboxType}
566+
// need to default $clearMissing to true, so the form is properly updated.
567+
$clearMissing = $child->getConfig()->getOption('clear_missing', false) ?: $clearMissing;
566568

567569
if ($isSubmitted || $clearMissing) {
568570
$child->submit($isSubmitted ? $submittedData[$name] : null, $clearMissing);

src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,45 @@ public function testSubmitWithEmptyValueAndTrueChecked()
136136
$this->assertSame('', $form->getViewData());
137137
}
138138

139+
public function testSubmitNestedCheckBoxWithEmptyValueAndFalseUnchecked()
140+
{
141+
$form = $this->factory->create('form', array('check' => true,))
142+
->add('check', 'checkbox', array(
143+
'value' => '',
144+
))
145+
;
146+
147+
$form->submit(null);
148+
149+
$this->assertFalse($form->get('check')->getData());
150+
$this->assertNull($form->get('check')->getViewData());
151+
}
152+
153+
public function testSubmitNestedCheckBoxWithEmptyValueAndFalseUncheckedWithClearMissingFalse()
154+
{
155+
$form = $this->factory->create('form', array('check' => true))
156+
->add('check', 'checkbox', array(
157+
'value' => '',
158+
))
159+
;
160+
161+
$form->submit(null, false);
162+
163+
$this->assertFalse($form->get('check')->getData());
164+
$this->assertNull($form->get('check')->getViewData());
165+
}
166+
167+
public function testSubmitNestedCheckboxWithEmptyValueAndTrueCheckedWithClearMissingFalse()
168+
{
169+
$form = $this->factory->create('checkbox', null, array(
170+
'value' => '',
171+
));
172+
$form->submit(true, false);
173+
174+
$this->assertTrue($form->getData());
175+
$this->assertSame('', $form->getViewData());
176+
}
177+
139178
/**
140179
* @dataProvider provideCustomModelTransformerData
141180
*/

0 commit comments

Comments
 (0)
0