Skip to content

Commit dbaddbb

Browse files
author
Thomas Chmielowiec
committed
[Form] Allow empty choices array for ChoiceType
1 parent 92cb685 commit dbaddbb

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function buildForm(FormBuilder $builder, array $options)
3737
throw new FormException('The "choice_list" must be an instance of "Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface".');
3838
}
3939

40-
if (!$options['choice_list'] && !$options['choices']) {
40+
if (!$options['choice_list'] && !is_array($options['choices']) && !$options['choices'] instanceof \Traversable) {
4141
throw new FormException('Either the option "choices" or "choice_list" must be set.');
4242
}
4343

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,4 +662,12 @@ public function testAdjustFullNameForMultipleNonExpanded()
662662

663663
$this->assertSame('name[]', $view->get('full_name'));
664664
}
665+
666+
// https://github.com/symfony/symfony/issues/3298
667+
public function testInitializeWithEmptyChoices()
668+
{
669+
$this->factory->createNamed('choice', 'name', null, array(
670+
'choices' => array(),
671+
));
672+
}
665673
}

0 commit comments

Comments
 (0)