Skip to content

[Twig bridge] Row attributes not output in bootstrap 4 form theme #34374

Closed
@loevgaard

Description

@loevgaard

Symfony version(s) affected: ^4.3.0

Description
In SF4.3 a row_attr was added to form types. These attributes are not outputted in the bootstrap 4 form theme

How to reproduce
Set row attr like this on a form type:

$builder
    ->add('field', TextType::class, [
        'row_attr' => [
            'data-test' => 'this attribute is not displayed'
        ]
    ])
;

Remember to use the bootstrap_4_layout.html.twig form theme. When rendering the form:

{{ form_row(form.field) }}

notice that there is no data-test attribute.

Possible Solution
Use something like the default theme:

{% with {attr: row_attr|default({})} %}{{ block('attributes') }}{% endwith %}

but of course use the bootstrap class, so maybe something like this:

{% with {attr: row_attr|default({'class': 'form-group'})} %}{{ block('attributes') }}{% endwith %}?

The problem with this is that if you set the row attr it would override the default attribute, which is not intended. So you need some kind of intelligent merge that can handle i.e. the default class and the user setting another class in the form type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions