Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mmarton opened this issue Jan 27, 2021 · 4 comments
Closed

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

mmarton opened this issue Jan 27, 2021 · 4 comments

Comments

@mmarton
Copy link

mmarton commented Jan 27, 2021

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.

@mmarton
Copy link
Author

mmarton commented Jan 27, 2021

@xabbuh Can you take a look? You fixed the related issue.

@xabbuh
Copy link
Member

xabbuh commented Jan 27, 2021

I probably just miss something, but what did you expect to see instead?

@mmarton
Copy link
Author

mmarton commented Jan 27, 2021

I would expect {{ field_label(form.field) }} to print out the same as {{ form_label(form.field) }} without the html wrapping. just the label text.
form.withoutLabel in my case.

@xabbuh
Copy link
Member

xabbuh commented Jan 28, 2021

Can you try out #40018?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants