8000 [Form] Fixed behavior of expanded multiple-choice field when submitte… · symfony/symfony@bc9bc4a · GitHub
[go: up one dir, main page]

Skip to content

Commit bc9bc4a

Browse files
committed
[Form] Fixed behavior of expanded multiple-choice field when submitted without ticks
1 parent 2e07256 commit bc9bc4a

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Symfony/Component/Form/Extension/Core/EventListener/FixCheckboxInputListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function onBindClientData(FilterDataEvent $event)
4141
$values = (array) $event->getData();
4242
$indices = $this->choiceList->getIndicesForValues($values);
4343

44-
$event->setData(array_combine($indices, $values));
44+
$event->setData(count($indices) > 0 ? array_combine($indices, $values) : array());
4545
}
4646

4747
static public function getSubscribedEvents()

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,29 @@ public function testBindMultipleExpanded()
399399
$this->assertNull($form[4]->getClientData());
400400
}
401401

402+
public function testBindMultipleExpandedEmpty()
403+
{
404+
$form = $this->factory->create('choice', null, array(
405+
'multiple' => true,
406+
'expanded' => true,
407+
'choices' => $this->choices,
408+
));
409+
410+
$form->bind(array());
411+
412+
$this->assertSame(array(), $form->getData());
413+
$this->assertFalse($form[0]->getData());
414+
$this->assertFalse($form[1]->getData());
415+
$this->assertFalse($form[2]->getData());
416+
$this->assertFalse($form[3]->getData());
417+
$this->assertFalse($form[4]->getData());
418+
$this->assertNull($form[0]->getClientData());
419+
$this->assertNull($form[1]->getClientData());
420+
$this->assertNull($form[2]->getClientData());
421+
$this->assertNull($form[3]->getClientData());
422+
$this->assertNull($form[4]->getClientData());
423+
}
424+
402425
public function testBindMultipleExpandedWithEmptyField()
403426
{
404427
$form = $this->factory->create('choice', null, array(

0 commit comments

Comments
 (0)
0