0
votes

I just started with Symfony2 and I am currently creating a form to edit user data.

I was able to create a select dropdown with this:

$builder->add('department', 'entity', array( 
        'em' => 'default', 
        'class' => 'My\SuperBundle\Entity\Department', 
        'multiple' => false, 
        'required' => true, 
        'query_builder' => function($repo) { 
            return $repo->createQueryBuilder('r')->orderBy('r.name', 'ASC'); 
        }, 
    ));

This is fine if I create a new user, but if I want to edit an existing one, the old value should be preselected (which it isn't). Also for a new user there should be a non-value (or empty) choice at the top so the user is forced to select something.

With the way described at http://symfony.com/doc/current/book/forms.html#embedded-forms I get the name of the current department of that user, but no selectable dropdown list.

Is this possible, and if so, how?

1

1 Answers

0
votes