Reputation:
I use this code to create a choice form:
$builder
->add('name', EntityType::class,[
'class' => MagList::class,
'label' => false,
'query_builder' => function(EntityRepository $rp){
return $rp->createQueryBuilder('u')
->orderBy('u.id', 'ASC');
},
'choice_label' => 'name',
'choice_value' => 'id',
'attr' => [
'id' => 'new_id',
'name' => 'new_name',
],
])
;
And in my page show this source:
...
<select id="mag_list_name" name="mag_list[name]" id="new_id" name="new_name">
...
How to remove default id and name in symfony form?
Upvotes: 3
Views: 1532
Reputation: 1129
How do you render your form? Might help if you post your twig file as well.
Anyway, if you use for example form_widget
as described here, you can set id
, name
and other attributes as you wish (docu). Example:
{{
form_widget(form.name, {
id: "new_id",
full_name: "new_name"
})
}}
Note that full_name
is the attribute for the HTML name attribute. If you use this solution, make sure that you render the other form components as well though and that they get the right attributes, as a label for example is dependent on the input id.
Upvotes: 1