Skip to content
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
4 changes: 3 additions & 1 deletion lib/bootstrap_form/inputs/inputs_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module InputsCollection
private

def inputs_collection(name, collection, value, text, options={})
options[:label] ||= { class: group_label_class(options[:layout]) }
options[:label] ||= { class: group_label_class(field_layout(options)) }
options[:inline] ||= layout_inline?(options[:layout])

form_group_builder(name, options) do
Expand All @@ -24,6 +24,8 @@ def inputs_collection(name, collection, value, text, options={})
end
end

def field_layout(options) = options[:layout] || (:inline if options[:inline] == true)

def group_label_class(field_layout)
if layout_horizontal?(field_layout)
group_label_class = "col-form-label #{label_col} pt-0"
Expand Down
5 changes: 2 additions & 3 deletions test/bootstrap_checkbox_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class BootstrapCheckboxTest < ActionView::TestCase
expected = <<~HTML
<input #{autocomplete_attr_55336} id="user_misc" name="user[misc][]" type="hidden" value="" />
<div class="mb-3">
<label class="form-label" for="user_misc">Misc</label>
<label class="form-check form-check-inline ps-0" for="user_misc">Misc</label>
<div class="form-check form-check-inline">
<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">
Expand All @@ -272,8 +272,7 @@ class BootstrapCheckboxTest < ActionView::TestCase
</div>
HTML

assert_equivalent_html expected, @builder.collection_check_boxes(:misc, collection, :id, :street,
inline: true)
assert_equivalent_html expected, @builder.collection_check_boxes(:misc, collection, :id, :street, inline: true)
end

test "collection_check_boxes renders with checked option correctly" do
Expand Down
2 changes: 1 addition & 1 deletion test/bootstrap_radio_button_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class BootstrapRadioButtonTest < ActionView::TestCase
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>
<label class="form-check form-check-inline ps-0" for="user_misc">Misc</label>
<div class="form-check form-check-inline">
<input class="form-check-input" id="user_misc_1" name="user[misc]" type="radio" value="1" />
<label class="form-check-label" for="user_misc_1"> Foo</label>
Expand Down