DoctrineModule
DoctrineModule copied to clipboard
ObjectSelect with optgroup support
It would be nice to be able to have an ObjectSelect that groups elements using optgroup html tag.
@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?
Hi! In my opinion this is a good idea!
Alright, I'll give this a shot though then within the coming weeks.
Thanks! :) I wait your PR.. Thanks for this feature
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 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.
Closing for - obviously - lack of interest/relevance.