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

Skip to content

Commit e071e65

Browse files
committed
updated fix
1 parent fa45a70 commit e071e65

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,49 @@ public function testSubmitWithEmptyValueAndTrueChecked()
136136
$this->assertSame('', $form->getViewData());
137137
}
138138

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

0 commit comments

Comments
 (0)
0