Reputation: 1060
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.
Upvotes: 3
Views: 1064
Reputation:
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' }) }}
Upvotes: 3