Skip to content

offset of checkbox in horizontal form not correctly inferred #175

@ghost

Description

As a checkbox has no label, it is positioned with an offset.
This should be inferred from the lable_col parameter of the form, but it seems to be set to a default value (col-sm-offset-2) for the checkbox

<%= bootstrap_form_for(Event.new, layout: :horizontal, label_col: 'col-sm-1', control_col: 'col-sm-3',
      :html => { :role => 'form', :class => 'form-horizontal' }) do |f| %>
  <%= f.text_field :name %>
  <%= f.form_group :offense do %>
    <%= f.check_box :offense %>
  <% end %>
  <%= f.number_field :points %>
<% end %>

produces this form content:

<div class="form-group">
    <label class="control-label col-sm-1" for="event_name">Name</label>
    <div class="col-sm-3">
        <input class="form-control" id="event_name" name="event[name]" type="text" />
    </div>
</div>
<div class="form-group">
    <div class="col-sm-3 col-sm-offset-2">
        <div class="checkbox">
            <label for="event_offense">
                <input name="event[offense]" type="hidden" value="0" />
                <input id="event_offense" name="event[offense]" type="checkbox" value="1" /> Offense
            </label>
        </div>
    </div>
</div>
<div class="form-group">
    <label class="control-label col-sm-1" for="event_points">Points</label>
    <div class="col-sm-3">
        <input class="form-control" id="event_points" name="event[points]" type="number" />
    </div>
</div>

When the form_group has the label_col option explicitly set

<%= f.form_group :offense, label_col: 'col-sm-1' do %>
  <%= f.check_box :offense %>
<% end %>

everything is fine.

-> seems that passing on the label_col option to the form_group does not work correctly.

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