public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('category', EntityType::class, [
'required' => false,
'class' => CashTransactionCategory::class,
'label' => 'Category *',
'attr' => [
'class' => 'js-cash_category',
'placeholder' => 'Select a category'
]
]);
}
This is a Select2 type input and I'm trying to set something like that data-flag="flag" for each attribute. The flag is set in database. It's possible to make a workaround and set for each row a data attribute ?
I figured out a simple solution and that's by mistake:
$builder
->add('category', EntityType::class, [
'required' => false,
'class' => CashTransactionCategory::class,
'label' => 'Category *',
'attr' => [
'class' => 'js-cash_category',
'placeholder' => 'Select a category',
],
'choice_attr' => function ($object) {
return ['data-flag' => $object->getFlag()];
}
]);
And that's because I'm using EntityType instead of ChoiceType. (Maybe this will help someone)
My Symfony version: 3.3.9
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