8000 [Form] Choice type int values (BC Fix) · symfony/symfony@ed211e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit ed211e9

Browse files
mcfedrfabpot
authored andcommitted
[Form] Choice type int values (BC Fix)
1 parent a0945fc commit ed211e9

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
171171
}
172172

173173
foreach ($data as $v) {
174-
if (null !== $v && !is_string($v)) {
175-
throw new TransformationFailedException('All choices submitted must be NULL or strings.');
174+
if (null !== $v && !is_string($v) && !is_int($v)) {
175+
throw new TransformationFailedException('All choices submitted must be NULL, strings or ints.');
176176
}
177177
}
178178
}, 256);

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,19 @@ public function testSubmitMultipleExpandedNumericChoices()
16891689
$this->assertNull($form[4]->getViewData());
16901690
}
16911691

1692+
public function testSubmitMultipleChoicesInts()
1693+
{
1694+
$form = $this->factory->create(static::TESTED_TYPE, null, array(
1695+
'multiple' => true,
1696+
'choices' => array_flip($this->numericChoicesFlipped),
1697+
'choices_as_values' => true,
1698+
));
1699+
1700+
$form->submit(array(1, 2));
1701+
1702+
$this->assertTrue($form->isSynchronized());
1703+
}
1704+
16921705
public function testSingleSelectedObjectChoices()
16931706
{
16941707
$view = $this->factory->create(static::TESTED_TYPE, $this->objectChoices[3], array(
@@ -2306,7 +2319,7 @@ public function testSubmitInvalidNestedValue($multiple, $expanded, $submissionDa
23062319

23072320
$form->submit($submissionData);
23082321
$this->assertFalse($form->isSynchronized());
2309-
$this->assertEquals('All choices submitted must be NULL or strings.', $form->getTransformationFailure()->getMessage());
2322+
$this->assertEquals('All choices submitted must be NULL, strings or ints.', $form->getTransformationFailure()->getMessage());
23102323
}
23112324

23122325
public function invalidNestedValueTestMatrix()

0 commit comments

Comments
 (0)
0