8000 [Twig bridge] Row attributes not output in bootstrap 4 form theme · Issue #34374 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

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
loevgaard opened this issue Nov 14, 2019 · 2 comments
Closed

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

loevgaard opened this issue Nov 14, 2019 · 2 comments

Comments

@loevgaard
Copy link
Contributor
loevgaard commented Nov 14, 2019

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.

@fancyweb
Copy link
Contributor

Duplicate of #33552, fixed in #33573 (waiting for merge).

@loevgaard
Copy link
Contributor Author

Beautiful, thanks!

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

No branches or pull requests

2 participants
0