I'm using the attr option to set the custom ID for my deletion form button:
{{ form_widget(form.delete, { 'label': 'myCustomLabel', 'attr': {'id': 'myCustomId'} }) }}
But it works with anything ('class' for example) except the 'id' attribute. The id is still 'form_delete' and I can't change it even with form builder:
$this->createFormBuilder(null, ['csrf_protection' => false])
->setAction($this->generateUrl('task_delete', array(
'prefix' => self::getTaskMapper()::getPrefix($task),
'id' => $task->getId()
)))->add('delete', SubmitType::class, [
'label' => 'delete',
'attr' => ['id' => 'MyCustomId']
])
->setMethod('DELETE')
->getForm();
Why is that the case? How do I overwrite it?
Form id overwriting works well.
Because you shouldn't be using attr. Just set the id on the main form_widget options:
form_widget(form.delete, { 'label': 'myCustomLabel','id': 'myCustomId' }) }}
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