I got a Form class with a non-mapped entity field in it:
->add('client', 'entity', array(
'class' => 'MyBundle:Client',
'property' => 'name',
'empty_value' => 'Select...',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('c')
->orderBy('c.name', 'ASC');
},
'mapped' => false,
))
which I create like this:
$form = $this->createForm(new MyType(),
$entity,
array('action' => $this->generateUrl('my_action'))
);
How can I set it's default value ? tried this, but not worked:
'data' => 23423, // id in table
'data' => 'Client name'
$form->setDefault('client', 'Client name'); // in controller
Please note that it's a non-mapped field.