Skip to content
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

Add margin below check boxes in the vertical layout #638

Merged
merged 1 commit into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ This generates the following HTML:
<label class="form-label" for="user_password">Password</label>
<input class="form-control" id="user_password" name="user[password]" type="password">
</div>
<div class="form-check">
<div class="form-check mb-3">
<input autocomplete="off" name="user[remember_me]" type="hidden" value="0">
<input class="form-check-input" id="user_remember_me" name="user[remember_me]" type="checkbox" value="1">
<label class="form-check-label" for="user_remember_me">Remember me</label>
Expand Down Expand Up @@ -154,7 +154,7 @@ This generates:
<input class="form-control" id="user_password" name="user[password]" type="password">
<small class="form-text text-muted">A good password should be at least six characters long</small>
</div>
<div class="form-check">
<div class="form-check mb-3">
<input autocomplete="off" name="user[remember_me]" type="hidden" value="0">
<input class="form-check-input" id="user_remember_me" name="user[remember_me]" type="checkbox" value="1">
<label class="form-check-label" for="user_remember_me">Remember me</label>
Expand Down Expand Up @@ -571,7 +571,7 @@ This generates:
<small class="form-text text-muted">Optional Help Text</small>
</div>
<div class="mb-3">
<div class="form-check">
<div class="form-check mb-3">
<input autocomplete="off" name="user[terms]" type="hidden" value="0">
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1">
<label class="form-check-label" for="user_terms">I agree to the Terms of Service</label>
Expand All @@ -595,7 +595,7 @@ This generates:
```html
<div class="mb-3">
<label class="form-label" for="user_terms">Optional Label</label>
<div class="form-check">
<div class="form-check mb-3">
<input autocomplete="off" name="user[terms]" type="hidden" value="0">
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1">
<label class="form-check-label" for="user_terms">
Expand Down Expand Up @@ -664,7 +664,7 @@ To render checkboxes as switches with Bootstrap 4.2+, use `switch: true`:
This generates:

```html
<div class="form-check form-switch">
<div class="form-check mb-3 form-switch">
<input autocomplete="off" name="user[remember_me]" type="hidden" value="0">
<input class="form-check-input" id="user_remember_me" name="user[remember_me]" type="checkbox" value="1">
<label class="form-check-label" for="user_remember_me">Remember me</label>
Expand Down Expand Up @@ -972,7 +972,7 @@ This generates:
<label class="form-label visually-hidden mr-sm-2" for="user_password">Password</label>
<input class="form-control" id="user_password" name="user[password]" type="password">
</div>
<div class="form-check form-check-inline">
<div class="form-check form-check-inline mb-3">
<input autocomplete="off" name="user[remember_me]" type="hidden" value="0">
<input class="form-check-input" id="user_remember_me" name="user[remember_me]" type="checkbox" value="1">
<label class="form-check-label" for="user_remember_me">Remember me</label>
Expand Down Expand Up @@ -1217,7 +1217,7 @@ This generates:
<label class="form-label" for="user_password">Password</label>
<input class="form-control" id="user_password" name="user[password]" type="password">
</div>
<div class="form-check">
<div class="form-check mb-3">
<input autocomplete="off" name="user[remember_me]" type="hidden" value="0">
<input class="form-check-input" custom="true" id="user_remember_me" name="user[remember_me]" type="checkbox" value="1">
<label class="form-check-label" for="user_remember_me">Remember me</label>
Expand Down
Binary file modified demo/doc/screenshots/bootstrap/index/02_inline_form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/00_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/02_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/21_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/33_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/39_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions lib/bootstrap_form/inputs/check_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def check_box_label_class(options)
def check_box_wrapper_class(options)
classes = ["form-check"]
classes << "form-check-inline" if layout_inline?(options[:inline])
classes << "mb-3" unless options[:multiple] || layout == :horizontal
classes << "form-switch" if options[:switch]
classes << options[:wrapper_class] if options[:wrapper_class].present?
classes.flatten.compact
Expand Down
34 changes: 17 additions & 17 deletions test/bootstrap_checkbox_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class BootstrapCheckboxTest < ActionView::TestCase

test "check_box is wrapped correctly" do
expected = <<~HTML
<div class="form-check">
<div class="form-check mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
<label class="form-check-label" for="user_terms">
Expand All @@ -20,7 +20,7 @@ class BootstrapCheckboxTest < ActionView::TestCase

test "check_box empty label" do
expected = <<~HTML
<div class="form-check">
<div class="form-check mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
<label class="form-check-label" for="user_terms">&#8203;</label>
Expand All @@ -32,7 +32,7 @@ class BootstrapCheckboxTest < ActionView::TestCase

test "disabled check_box has proper wrapper classes" do
expected = <<~HTML
<div class="form-check">
<div class="form-check mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" disabled="disabled" />
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" disabled="disabled" />
<label class="form-check-label" for="user_terms">
Expand All @@ -45,7 +45,7 @@ class BootstrapCheckboxTest < ActionView::TestCase

test "check_box label allows html" do
expected = <<~HTML
<div class="form-check">
<div class="form-check mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
<label class="form-check-label" for="user_terms">
Expand All @@ -58,7 +58,7 @@ class BootstrapCheckboxTest < ActionView::TestCase

test "check_box accepts a block to define the label" do
expected = <<~HTML
<div class="form-check">
<div class="form-check mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
<label class="form-check-label" for="user_terms">
Expand All @@ -71,7 +71,7 @@ class BootstrapCheckboxTest < ActionView::TestCase

test "check_box accepts a custom label class" do
expected = <<~HTML
<div class="form-check">
<div class="form-check mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
<label class="form-check-label btn" for="user_terms">
Expand All @@ -84,7 +84,7 @@ class BootstrapCheckboxTest < ActionView::TestCase

test "check_box 'id' attribute is used to specify label 'for' attribute" do
expected = <<~HTML
<div class="form-check">
<div class="form-check mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input" id="custom_id" name="user[terms]" type="checkbox" value="1" />
<label class="form-check-label" for="custom_id">
Expand All @@ -97,7 +97,7 @@ class BootstrapCheckboxTest < ActionView::TestCase

test "check_box responds to checked_value and unchecked_value arguments" do
expected = <<~HTML
<div class="form-check">
<div class="form-check mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="no" />
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="yes" />
<label class="form-check-label" for="user_terms">
Expand All @@ -110,7 +110,7 @@ class BootstrapCheckboxTest < ActionView::TestCase

test "inline checkboxes" do
expected = <<~HTML
<div class="form-check form-check-inline">
<div class="form-check form-check-inline mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
<label class="form-check-label" for="user_terms">
Expand All @@ -125,7 +125,7 @@ class BootstrapCheckboxTest < ActionView::TestCase
expected = <<~HTML
<form accept-charset="UTF-8" action="/users" class="new_user col-auto g-3" id="new_user" method="post">
#{'<input name="utf8" type="hidden" value="&#x2713;"/>' unless ::Rails::VERSION::STRING >= '6'}
<div class="form-check form-check-inline">
<div class="form-check form-check-inline mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
<label class="form-check-label" for="user_terms">
Expand All @@ -142,7 +142,7 @@ class BootstrapCheckboxTest < ActionView::TestCase

test "disabled inline check_box" do
expected = <<~HTML
<div class="form-check form-check-inline">
<div class="form-check form-check-inline mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" disabled="disabled" />
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" disabled="disabled" />
<label class="form-check-label" for="user_terms">
Expand All @@ -156,7 +156,7 @@ class BootstrapCheckboxTest < ActionView::TestCase

test "inline checkboxes with custom label class" do
expected = <<~HTML
<div class="form-check form-check-inline">
<div class="form-check form-check-inline mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
<label class="form-check-label btn" for="user_terms">
Expand Down Expand Up @@ -498,7 +498,7 @@ class BootstrapCheckboxTest < ActionView::TestCase

test "check_box skip label" do
expected = <<~HTML
<div class="form-check">
<div class="form-check mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input position-static" id="user_terms" name="user[terms]" type="checkbox" value="1" />
</div>
Expand All @@ -508,7 +508,7 @@ class BootstrapCheckboxTest < ActionView::TestCase

test "check_box hide label" do
expected = <<~HTML
<div class="form-check">
<div class="form-check mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input position-static" id="user_terms" name="user[terms]" type="checkbox" value="1" />
<label class="form-check-label visually-hidden" for="user_terms">I agree to the terms</label>
Expand Down Expand Up @@ -580,7 +580,7 @@ class BootstrapCheckboxTest < ActionView::TestCase
expected = <<~HTML
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">
#{'<input name="utf8" type="hidden" value="&#x2713;"/>' unless ::Rails::VERSION::STRING >= '6'}
<div class="form-check">
<div class="form-check mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input is-invalid" id="user_terms" name="user[terms]" type="checkbox" value="1" />
<label class="form-check-label" for="user_terms">
Expand All @@ -598,7 +598,7 @@ class BootstrapCheckboxTest < ActionView::TestCase

test "check box with custom wrapper class" do
expected = <<~HTML
<div class="form-check custom-class">
<div class="form-check mb-3 custom-class">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
<label class="form-check-label" for="user_terms">
Expand All @@ -611,7 +611,7 @@ class BootstrapCheckboxTest < ActionView::TestCase

test "inline check box with custom wrapper class" do
expected = <<~HTML
<div class="form-check form-check-inline custom-class">
<div class="form-check form-check-inline mb-3 custom-class">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
<label class="form-check-label" for="user_terms">
Expand Down
4 changes: 2 additions & 2 deletions test/bootstrap_fields_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class BootstrapFieldsTest < ActionView::TestCase

test "check_box fields are wrapped correctly" do
expected = <<~HTML
<div class="form-check">
<div class="form-check mb-3">
<input #{autocomplete_attr} name="user[misc]" type="hidden" value="0"/>
<input class="form-check-input" id="user_misc" name="user[misc]" type="checkbox" value="1"/>
<label class="form-check-label" for="user_misc">Misc</label>
Expand All @@ -271,7 +271,7 @@ class BootstrapFieldsTest < ActionView::TestCase

test "switch-style check_box fields are wrapped correctly" do
expected = <<~HTML
<div class="form-check form-switch">
<div class="form-check mb-3 form-switch">
<input #{autocomplete_attr} name="user[misc]" type="hidden" value="0"/>
<input class="form-check-input" id="user_misc" name="user[misc]" type="checkbox" value="1"/>
<label class="form-check-label" for="user_misc">Misc</label>
Expand Down
8 changes: 4 additions & 4 deletions test/bootstrap_form_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BootstrapFormTest < ActionView::TestCase
<input class="form-control" id="user_email" name="user[email]" type="email" value="[email protected]" />
</div>
</div>
<div class="form-check">
<div class="form-check mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
<label class="form-check-label" for="user_terms">I agree to the terms</label>
Expand Down Expand Up @@ -74,7 +74,7 @@ class BootstrapFormTest < ActionView::TestCase
<label class="form-label mr-sm-2 required" for="user_email">Email</label>
<input class="form-control" id="user_email" name="user[email]" type="email" value="[email protected]" />
</div>
<div class="form-check form-check-inline">
<div class="form-check form-check-inline mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
<label class="form-check-label" for="user_terms">I agree to the terms</label>
Expand Down Expand Up @@ -136,7 +136,7 @@ class BootstrapFormTest < ActionView::TestCase
<label class="form-label mr-sm-2 required" for="user_email">Email</label>
<input class="form-control" id="user_email" name="user[email]" type="email" value="[email protected]" />
</div>
<div class="form-check form-check-inline">
<div class="form-check form-check-inline mb-3">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
<label class="form-check-label" for="user_terms">I agree to the terms</label>
Expand Down Expand Up @@ -412,7 +412,7 @@ class BootstrapFormTest < ActionView::TestCase
expected = <<~HTML
<form accept-charset="UTF-8" action="/users" method="post">
#{'<input name="utf8" type="hidden" value="&#x2713;"/>' unless ::Rails::VERSION::STRING >= '6'}
<div class="form-check">
<div class="form-check mb-3">
<input class="form-check-input" id="#{id}" name="#{name}" type="checkbox" value="1" />
<input #{autocomplete_attr} name="#{name}" type="hidden" value="0" />
<label class="form-check-label" for="#{id}"> Misc</label>
Expand Down