I am trying to use the select2 for my symfony2 entity fields.
I created an extension of the entity field, a twig template and a Model Transformer for it. Rendering works just fine, however I am having problems with submitting the fields.
With the origin format, the values are sent like that:
Content-Disposition: form-data; name="com_bundle_book[series]" 1
And for an entity with multiple s
Content-Disposition: form-data; name="com_bundle_book[author][]" 1
Content-Disposition: form-data; name="com_bundle_book[author][]" 3
select2's behaviour is to replace the existing field with a hidden field. The sent data looks like that:
Content-Disposition: form-data; name="com_bundle_book[series]" TraLiRo
Content-Disposition: form-data; name="com_bundle_book[author][]" Ferdinand,Hans
I hoped to sort this out with the modelTransformer, but instead I get an error (invalid value) for both fields while the modelTransformer is never called.
I tried it with an extension of entity and by extending entity itself. My services:
com_bundle.tag_type_extension:
class: ...\Form\Extension\TagTypeExtension
tags:
- { name: form.type_extension, alias: entity }
arguments: [@doctrine.orm.entity_manager]
com_bundle.form.type.tagType_entity:
class: ...\Form\Extension\TagTypeExtension2
tags:
- { name: form.type, alias: tagType_entity }
arguments: [@doctrine.orm.entity_manager]
The classes:
How do I fix this?
Update
Form is built like this:
$builder
->add('author',
'entity',
array(
'select2' => true,
'multiple' => true,
'class' => 'Bundle:Author',
'property' => 'name'
)
)