15

Env: Symfony2 2.7 / Propel 1.6

I've created a choice form type like that:

    $builder->add('mychoice', 'model', array(
            'class' => 'Foo\\Bar',
            'query' => FooBarQuery::create()->filterBySomething(true),
            'group_by' => 'example',
            'property' => 'title',
            'multiple' => false,
            'expanded' => false,
        ));

The rendering choice list is ok with good optgroup select options but the title's property is not displayed - id's property instead. If I remove the group_by option, the title property is well displayed.

What's wrong?

Lionel
  • 387
  • 3
  • 18

1 Answers1

1

Would this work?

   $builder->add(
        'mychoice',
        'entity',
        array(              
            'class' => 'Foo\\Bar',
            'choice_label' => 'title',
            'multiple' => false,
            'expanded' => false,
        )
    );

Set the type to entity and add a choice_label property and the property you want to be displayed.

George Irimiciuc
  • 4,573
  • 8
  • 44
  • 88
  • "entity" is only for doctrine / "model" is the equivalent for propel http://propelorm.org/Propel/cookbook/symfony2/mastering-symfony2-forms-with-propel.html#the-modeltype – Lionel Sep 24 '15 at 07:48
  • Well there it says 'index_property' => 'slug' /** If you want to use a specifiq unique column for key to not expose the PK **/ . Did you try that, as well? – George Irimiciuc Sep 24 '15 at 08:27
  • as it is said, it's for the key column > i'm searching the right config for the display, not the key - BTW, this bugs occurs only with the "group_by" option, it works fine otherwise – Lionel Sep 24 '15 at 08:53