Skip to content

Commit 273db0c

Browse files
authored
Merge pull request #778 from lcreid/777-inline-true-for-collections
`inline: true` generates the same CSS for the collection label as lay…
2 parents d652b17 + a529e27 commit 273db0c

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

lib/bootstrap_form/inputs/inputs_collection.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module InputsCollection
88
private
99

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

1414
form_group_builder(name, options) do
@@ -24,6 +24,8 @@ def inputs_collection(name, collection, value, text, options={})
2424
end
2525
end
2626

27+
def field_layout(options) = options[:layout] || (:inline if options[:inline] == true)
28+
2729
def group_label_class(field_layout)
2830
if layout_horizontal?(field_layout)
2931
group_label_class = "col-form-label #{label_col} pt-0"

test/bootstrap_checkbox_test.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class BootstrapCheckboxTest < ActionView::TestCase
256256
expected = <<~HTML
257257
<input #{autocomplete_attr_55336} id="user_misc" name="user[misc][]" type="hidden" value="" />
258258
<div class="mb-3">
259-
<label class="form-label" for="user_misc">Misc</label>
259+
<label class="form-check form-check-inline ps-0" for="user_misc">Misc</label>
260260
<div class="form-check form-check-inline">
261261
<input class="form-check-input" id="user_misc_1" name="user[misc][]" type="checkbox" value="1" />
262262
<label class="form-check-label" for="user_misc_1">
@@ -272,8 +272,7 @@ class BootstrapCheckboxTest < ActionView::TestCase
272272
</div>
273273
HTML
274274

275-
assert_equivalent_html expected, @builder.collection_check_boxes(:misc, collection, :id, :street,
276-
inline: true)
275+
assert_equivalent_html expected, @builder.collection_check_boxes(:misc, collection, :id, :street, inline: true)
277276
end
278277

279278
test "collection_check_boxes renders with checked option correctly" do

test/bootstrap_radio_button_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class BootstrapRadioButtonTest < ActionView::TestCase
209209
collection = [Address.new(id: 1, street: "Foo"), Address.new(id: 2, street: "Bar")]
210210
expected = <<~HTML
211211
<div class="mb-3">
212-
<label class="form-label" for="user_misc">Misc</label>
212+
<label class="form-check form-check-inline ps-0" for="user_misc">Misc</label>
213213
<div class="form-check form-check-inline">
214214
<input class="form-check-input" id="user_misc_1" name="user[misc]" type="radio" value="1" />
215215
<label class="form-check-label" for="user_misc_1"> Foo</label>

0 commit comments

Comments
 (0)