Closed
Closed
Copy link
Description
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | maybe |
RFC? | no |
Symfony version | 3.4.6 |
When rendering a CheckboxType form input in a view, instead of separating label, errors and widget, Symfony renders the whole row of the input.
TestType.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',
]
]);
}
test-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
is empty and form_widget
renders what form_row
should render.
I can't find if it's an expected behaviour.