In a Symfony form I have one field called slot that matches an entity with a custom query. let's say something like this:
->add('slot', 'entity', array(
'label' => 'Slot',
'class' => 'FooBarBundle:Slot',
'property' => 'name',
'required' => false,
'query_builder' => function(\Foo\BarBundle\Entity\SlotRepository $er) use ($ids) {
return $er->createQueryBuilder('u')
->where('u.id IN(:ids)')->setParameter('ids', $ids);
}
))
so far every thing works. The slot is a ManyToOne matching on the Team entity (for which the form is), so there can only be one slot selected at a time. As I said, every thing going according to plan. The user can select a slot and save it and every one's happy.
The trouble starts when you try to "unselect" a slot (yep that has to be possible). So I need to add a none value with a caption like None of the listed items or what ever. The question is how can I do that?
'empty_data' => null,'empty_value' => null?'empty_value' => 'None of the listed items'would do the job.