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

Bootstrap 4 Form Template can not correctly render inline checkboxes #25099

Copy link
Copy link
Closed
@sschueller

Description

@sschueller
Issue body actions
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.4

According to the bootstrap documentation an inline list of checkboxes should be rendered as follows

<div class="form-check form-check-inline">
  <label class="form-check-label">
    <input class="form-check-input" type="checkbox" id="inlineCheckbox1" value="option1"> 1
  </label>
</div>
<div class="form-check form-check-inline">
  <label class="form-check-label">
    <input class="form-check-input" type="checkbox" id="inlineCheckbox2" value="option2"> 2
  </label>
</div>
<div class="form-check form-check-inline disabled">
  <label class="form-check-label">
    <input class="form-check-input" type="checkbox" id="inlineCheckbox3" value="option3" disabled> 3
  </label>
</div>

However it appears impossible to achieve this using the bootstrap 4 templates (symfony/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig) even with splitting the checkboxes in the form. For example:

{% for checkbox in form.myitem.children  %}
  {{ form_widget(checkbox) }}
{% endfor %}

Result:

<div class="form-check">
  <label class="form-check-label">
    <input class="form-check-input" ... /> Label
  </label>
</div>
<div class="form-check">
  <label class="form-check-label">
    <input class="form-check-input" ... /> Label
  </label>
</div>

Adding the required form-check-inline to the div, fixes the issue. However then there is no way to not have them be inline.

{% block checkbox_widget -%}
    {%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
    {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%}
    {% if 'checkbox-inline' in parent_label_class %}
        {{- form_label(form, null, { widget: parent() }) -}}
    {% else -%}
        <div class="form-check{{ not valid ? ' form-control is-invalid' }} form-check-inline">
            {{- form_label(form, null, { widget: parent() }) -}}
        </div>
    {%- endif -%}
{%- endblock checkbox_widget %}

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.