[Form] Fixed behavior of expanded multiple-choice field when submitted without ticks
This commit is contained in:
parent
2e07256921
commit
bc9bc4af5d
@ -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()
|
||||
|
@ -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(
|
||||
|
Reference in New Issue
Block a user