I try to render a form input in a view but instead of separating label
, errors
and widget
, it renders the whole row
of the input.
MyType.php
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email', EmailType::class, [
'label' => 'Email',
'required' => true,
])
->add('emailIsPublic', CheckboxType::class, [
'label' => 'Make e-mail public (can be seen by everyone)',
'required' => false,
'attr' => [
'class' => 'switch',
]
])
->add('submit', SubmitType::class, [
'label' => 'Save changes',
'attr' => [
'class' => 'btn btn-outline-primary float-right',
]
]);
}
my-view.html.twig
{{ form_start(edit_form) }}
<div>
{{ form_label(edit_form.emailIsPublic) }}
</div>
<div>
{{ form_errors(edit_form.emailIsPublic) }}
</div>
<div>
{{ form_widget(edit_form.emailIsPublic) }}
</div>
{{ form_end(edit_form, {'render_rest': false}) }}
Generated HTML
<form name="appbundle_my" method="post">
<div></div>
<div></div>
<div>
<div class="form-check">
<label class="form-check-label">
<input id="appbundle_my_emailIsPublic" name="appbundle_my[emailIsPublic]" class="switch form-check-input" value="1" type="checkbox"> Make e-mail public (can be seen by everyone)
</label>
</div>
</div>
</form>
As we can see in the generated HTML, form_label
and form_errors
are empty and form_widget
renders what form_row
should render. Why?