kingtut007
kingtut007

Reputation: 89

Symfony3 CollectionType of ChoiceType shows nothing

I tried the example from the site at: https://symfony.com/doc/current/reference/forms/types/collection.html

I tried this block of code:

$builder->add('favorite_cities', CollectionType::class, array(
'entry_type'   => ChoiceType::class,
'entry_options'  => array(
    'choices'  => array(
        'Nashville' => 'nashville',
        'Paris'     => 'paris',
        'Berlin'    => 'berlin',
        'London'    => 'london',
    ),
)));

But it shows nothing in the form when I render it. (there is nothing wrong with my form code, it renders other fields as soon as I change it).

I wanted to know if someone else could try it and see if they are getting the same thing / or if I am doing something wrong.

Thanks..

Upvotes: 0

Views: 1153

Answers (1)

Austyn
Austyn

Reputation: 51

I had the same issue and finally figured this out. Unless data is passed as well then no options show up at all.

$builder->add('favorite_cities', CollectionType::class, array(
    'entry_type'   => ChoiceType::class,
    'entry_options'  => array(
        'choices'  => array(
            'Nashville' => 'nashville',
            'Paris'     => 'paris',
            'Berlin'    => 'berlin',
            'London'    => 'london',
        ),
    ),
    'data'  => array(
        'Input Label Here' => 'paris',
    ),
));

Upvotes: 2

Related Questions