Answer the question
In order to leave comments, you need to log in
How to add data-type to option in select using Symfony form builder?
I'm creating a form using Symfony's built-in form builder. $builder->add('category', 'select');
category is a reference to an entity, this entity, in addition to id and name, also has a type. How can I add this line so that when creating a select {{ form_widget(form.category) }}
, the data-type attribute with the value from the type field is added to the option.
Answer the question
In order to leave comments, you need to log in
$builder->add('category', null, [
'choice_attr' => function ($entity, $currentChoiceKey) {
return ['data-type' => $entity->getType()];
}
]);
something like this
zeka.kiev.ua/symfony2-form-%D0%B4%D0%BE%D0%B1%D0%B...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question