In Symfony2 I have BandType
, where I add the entity Tag
:
->add('tags', 'entity', [
'label' => 'Tags',
'class' => 'DbBundle:Tag',
'property' => 'title',
'multiple' => true,
])
This generate multiple select element, where I can choose existing tags from database (Doctrine). But I need to add new tags dynamicaly, which don't exist yet.
On a client side I use jQuery plugin Selectize.js, which allows me to add new tag to select box. But after submit form the new tags are not saved.
So my question is - what is the clearest way to persist new items from select box (entity field type)?
Use a Data Transformer for your entity. And in the reverseTransform method, if you don't find the newly added band, simply create it there instead of throwing a TransformationFailedException.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With