Skip to content

[Form] field_label form helper only shows explicitly set label #40007

Closed
@mmarton

Description

@mmarton

Symfony version(s) affected: 5.2.*

Description
I was happy when i saw that the today released 5.2.2 version fixed the bug #39591
And it sure doesn't give me typeexception like before.... but it doesn't give me the expected label neither...
Or maybe I totally misunderstand the concept...

How to reproduce

class IndexController extends AbstractController
{
    /** @Route("/") */
    public function index(): Response
    {
        $form = $this->createFormBuilder(null, ['label_format' => 'form.%name%'])
            ->add('withLabel', TextType::class, ['label' => 'I.am.label'])
            ->add('withoutLabel', TextType::class)
            ->getForm();

        return $this->render('index/index.html.twig', ['form' => $form->createView()]);
    }
}
{% extends 'base.html.twig' %}

{% form_theme form 'bootstrap_4_horizontal_layout.html.twig' %}

{% block stylesheets %}
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
{% endblock %}

{% block body %}
    {{ form_start(form) }}
        <div class="row">
            <label class="col-2">{{ field_label(form.withLabel) }}</label>
            <div class="col-2">{{ form_label(form.withLabel) }}</div>
            <div class="col-8">{{ form_widget(form.withLabel) }}</div>

            <label class="col-2">{{ field_label(form.withoutLabel) }}</label>
            <div class="col-2">{{ form_label(form.withoutLabel) }}</div>
            <div class="col-8">{{ form_widget(form.withoutLabel) }}</div>
        </div>
    {{ form_end(form) }}
{% endblock %}

result: no label where it is not explicitly set:
image

Additional context
Maybe the #39591 was just the symptom and the problem is the absence of the label.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions