Pregunta

I have this Symfony form, it displays the values of the entity 'Manifestation' that has a many to many relationship.

So I do: ->add('manifestations').

But when I try to add an empty_value 'All' in the select list, it doesn't work!

Can any one help me ? Thanks

   public function buildForm(FormBuilderInterface $builder, array $options) {
    $builder
            ->add('manifestations', 'entity', array(
                'class' => 'PrifProtocoleBundle:Manifestation',
                'multiple' => true,
                'property' => 'name',
                'empty_value' => 'All',
                'required' => false,));
}
¿Fue útil?

Solución

empty values New in Symfony version 2.3 .

empty values are also supported if the expanded option is set to true like Symfony 2.3 Documentation

  public function buildForm(FormBuilderInterface $builder, array $options) {
    $builder
            ->add('manifestations', 'entity', array(
                'class' => 'PrifProtocoleBundle:Manifestation',
                'multiple' => true,
                'expanded' => true,  
                'property' => 'name',
                'empty_value' => 'All',
                'required' => false,));
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top