Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Help message not displayed for Checkbox in 3 themes (bootstrap3, foundation5) #35006

Closed
@emmanuelballery

Description

@emmanuelballery

Symfony version(s) affected: >4.1.0

Description

bootstrap_3_layout.html.twig, bootstrap_3_horizontal_layout.html.twig and foundation_5_layout.html.twig do not support help message for checkbox field ;

Originally reported in #29135 but closed due to lack of feedback.

How to reproduce

Standalone Controller: src/Controller/DefaultController.php

<?php declare(strict_types=1);

namespace App\Controller;

use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class DefaultController extends AbstractController
{
    /**
     * @Route(methods={"GET"})
     */
    public function index(): Response
    {
        $form = $this
            ->createFormBuilder()
            ->add('isChecked', CheckboxType::class, ['help' => 'foo'])
            ->getForm();

        return $this->render('foo.html.twig', [
            'form' => $form->createView(),
        ]);
    }
}

Template: templates/foo.html.twig

{#
form_div_layout.html.twig
form_table_layout.html.twig
bootstrap_3_layout.html.twig
bootstrap_3_horizontal_layout.html.twig
bootstrap_4_layout.html.twig
bootstrap_4_horizontal_layout.html.twig
foundation_5_layout.html.twig
#}

<h1>bootstrap_3_layout.html.twig</h1>
{% form_theme form 'bootstrap_3_layout.html.twig' %}
{{ form(form) }}

image
image

Possible Solution

form_help is not called in bootstrap_3_layout.html.twig or bootstrap_3_horizontal_layout.html.twig or foundation_5_layout.html.twig in the block checkbox_row.

See bootstrap_3_layout.html.twig here:

{% block checkbox_row -%}
    <div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group' ~ (not valid ? ' has-error'))|trim})} %}{{ block('attributes') }}{% endwith %}>
        {{- form_widget(form) -}}
        {{- form_errors(form) -}}
    </div>
{%- endblock checkbox_row %}

You can spot the difference with the same block in bootstrap_4_horizontal_layout.html.twig:

{% block checkbox_row -%}
    <div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group row')|trim})} %}{{ block('attributes') }}{% endwith %}>{#--#}
        <div class="{{ block('form_label_class') }}"></div>{#--#}
        <div class="{{ block('form_group_class') }}">
            {{- form_widget(form) -}}
            {{- form_help(form) -}}
        </div>{#--#}
    </div>
{%- endblock checkbox_row %}

It was fixed for bootstrap 4 in 68a9a07.

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