Skip to content

Commit

Permalink
[Form] Allow empty choices array for ChoiceType
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Chmielowiec committed Feb 11, 2012
1 parent 92cb685 commit dbaddbb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Expand Up @@ -37,7 +37,7 @@ public function buildForm(FormBuilder $builder, array $options)
throw new FormException('The "choice_list" must be an instance of "Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface".');
}

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

Expand Down
Expand Up @@ -662,4 +662,12 @@ public function testAdjustFullNameForMultipleNonExpanded()

$this->assertSame('name[]', $view->get('full_name'));
}

// https://github.com/symfony/symfony/issues/3298
public function testInitializeWithEmptyChoices()
{
$this->factory->createNamed('choice', 'name', null, array(
'choices' => array(),
));
}
}

0 comments on commit dbaddbb

Please sign in to comment.