How do I overwrite the id of a form button?
I am using a parameter attr
to set a custom id for a delete form button:
{{ form_widget(form.delete, { 'label': 'myCustomLabel', 'attr': {'id': 'myCustomId'} }) }}
But it works with anything ( 'class' ) other than the 'id' attribute . The id is still 'form_delete' and I cannot change it even with the 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 this so? How to rewrite it?
Rewriting the form id works well.
+3
source to share