Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Form] Add option to add a class to <div class="form-check"> (radio+checkbox) #36502

Copy link
Copy link
Closed
@ThomasLandauer

Description

@ThomasLandauer
Issue body actions

It would be nice to have an option to add a class name here (Bootstrap theme):
https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig#L193

That is the <div> around each radio button / checkbox.

Suggested name: choice_row_attr - since choice_attr addresses the <input>, and row_attr the <div> containing all the radios.

So if you either do:

public function finishView(FormView $view, FormInterface $form, array $options)
{
    $view['field'][0]->vars['choice_row_attr'] = ['class' => 'foo'];
}

... or ...

{% for key, field in form.field.children %}
    {{ form_widget(field, {'choice_row_attr': {'class':'foo'}}) }}
{% endfor %}

...the outcome would be:

<div class="form-check foo">
  <input type="radio" ...>
</div>
<div class="form-check foo">
  <input type="radio" ...>
</div>
<div class="form-check foo">
  <input type="radio" ...>
</div>

My use case:
I'm having a list of like 20 radio buttons, and depending on the user's selection in another field, some of them get hidden (with JavaScript).
Other use case would be to highlight some radios.

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.