DoctrineModule icon indicating copy to clipboard operation
DoctrineModule copied to clipboard

ObjectSelect with optgroup support

Open sparrowek opened this issue 11 years ago • 6 comments

It would be nice to be able to have an ObjectSelect that groups elements using optgroup html tag.

sparrowek avatar Jan 21 '14 09:01 sparrowek

@gianarb how would you feel about an option where the optgroup is defined by a second field of the same table? I.e:

Items
id | title | group
1 | Foo | foo
2 | FooFoo | foo
3 | Bar | bar

And the options then would look similar to this:

$this->add([
    'type'    => 'DoctrineModule\Form\Element\ObjectSelect',
    'name'    => 'type',
    'options' => [
        'label'              => 'Items',
        'object_manager'     => $objectManager,
        'target_class'       => 'Entity\Item',
        'display_empty_item' => true,
        'empty_item_label'   => '--- (required) choose an item ---',
        'property' => 'title',
        'optgroup_property' => 'group'
    ]
]);

And then stuff being rendered accordingly?

I'll be working this within the current project im working on and could easily do it as a proper doctrineModule feature as well. The thing is that this is a quite "local solution".

It may be cleaner to have a separate table for optgroups and then connect the tables (DB wise).

thoughts?

manuakasam avatar Apr 30 '15 12:04 manuakasam

Hi! In my opinion this is a good idea!

gianarb avatar Apr 30 '15 12:04 gianarb

Alright, I'll give this a shot though then within the coming weeks.

manuakasam avatar Apr 30 '15 12:04 manuakasam

Thanks! :) I wait your PR.. Thanks for this feature

gianarb avatar Apr 30 '15 12:04 gianarb

Thanks @manuakasam. I really like this feature. Did you think of a label generator for the optgroups? I would do a PR myself but i'm not that familiar with the doctrine code yet.

xelax90 avatar May 13 '15 09:05 xelax90

@xelax90 that wouldn't go hand in hand with the current implementation. As you do need an identifier within the database for the current implementation to work. And in this case a label_generator (for the optgroup-title) would not be required.

The options itself are able to generate their label as usual.

manuakasam avatar May 13 '15 11:05 manuakasam

Closing for - obviously - lack of interest/relevance.

driehle avatar Oct 18 '23 02:10 driehle