Skip to content

Commit

Permalink
Enable include_hidden option (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
a5-stable authored Jan 16, 2022
1 parent 1c7688d commit c07c482
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [#572](https://github.com/bootstrap-ruby/bootstrap_form/issues/572): Simplify the formatting of the file upload control to follow the new Bootstrap 5 styles
* [#573](https://github.com/bootstrap-ruby/bootstrap_form/issues/573): Add support for Bootstrap 5's floating labels

* [#215](https://github.com/bootstrap-ruby/bootstrap_form/issues/215): Add `include_hidden` option to `check_box`
### Bugfixes

* [#582](https://github.com/bootstrap-ruby/bootstrap_form/issues/582): Fix tests in bootstrap-5 branch, removes Rubocop offenses, and adds testing with Rails 6.1.
Expand Down
4 changes: 3 additions & 1 deletion lib/bootstrap_form/inputs/collection_check_boxes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def collection_check_boxes_with_bootstrap(*args)
options[:multiple] = true
check_box(name, options, value, nil)
end
hidden_field(args.first, value: "", multiple: true).concat(html)

include_hidden = args.extract_options!.symbolize_keys!.delete(:include_hidden) { true }
include_hidden ? hidden_field(args.first, value: "", multiple: true).concat(html) : html
end

bootstrap_alias :collection_check_boxes
Expand Down
19 changes: 19 additions & 0 deletions test/bootstrap_checkbox_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,25 @@ class BootstrapCheckboxTest < ActionView::TestCase
:street, checked: collection)
end

test "collection_check_boxes renders with include_hidden options correctly" do
collection = [Address.new(id: 1, street: "Foo"), Address.new(id: 2, street: "Bar")]
expected = <<~HTML
<div class="mb-3">
<label class="form-label" for="user_misc">Misc</label>
<div class="form-check">
<input class="form-check-input" id="user_misc_1" name="user[misc][]" type="checkbox" value="1" />
<label class="form-check-label" for="user_misc_1">Foo</label>
</div>
<div class="form-check">
<input class="form-check-input" id="user_misc_2" name="user[misc][]" type="checkbox" value="2" />
<label class="form-check-label" for="user_misc_2">Bar</label>
</div>
</div>
HTML

assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street, include_hidden: false)
end

test "check_box skip label" do
expected = <<~HTML
<div class="form-check">
Expand Down

0 comments on commit c07c482

Please sign in to comment.