[Form] Fixed behavior of expanded multiple-choice field when submitted without ticks

This commit is contained in:
Bernhard Schussek 2012-04-10 17:42:05 +02:00
parent 2e07256921
commit bc9bc4af5d
2 changed files with 24 additions and 1 deletions

View File

@ -41,7 +41,7 @@ class FixCheckboxInputListener implements EventSubscriberInterface
$values = (array) $event->getData();
$indices = $this->choiceList->getIndicesForValues($values);
$event->setData(array_combine($indices, $values));
$event->setData(count($indices) > 0 ? array_combine($indices, $values) : array());
}
static public function getSubscribedEvents()

View File

@ -399,6 +399,29 @@ class ChoiceTypeTest extends TypeTestCase
$this->assertNull($form[4]->getClientData());
}
public function testBindMultipleExpandedEmpty()
{
$form = $this->factory->create('choice', null, array(
'multiple' => true,
'expanded' => true,
'choices' => $this->choices,
));
$form->bind(array());
$this->assertSame(array(), $form->getData());
$this->assertFalse($form[0]->getData());
$this->assertFalse($form[1]->getData());
$this->assertFalse($form[2]->getData());
$this->assertFalse($form[3]->getData());
$this->assertFalse($form[4]->getData());
$this->assertNull($form[0]->getClientData());
$this->assertNull($form[1]->getClientData());
$this->assertNull($form[2]->getClientData());
$this->assertNull($form[3]->getClientData());
$this->assertNull($form[4]->getClientData());
}
public function testBindMultipleExpandedWithEmptyField()
{
$form = $this->factory->create('choice', null, array(