Skip to content

Commit 437a90c

Browse files
committed
wrapper: { class: false } fix and tests
1 parent b88d6f8 commit 437a90c

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

lib/bootstrap_form/inputs/check_box.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ def check_box_label_class(options)
8686
def check_box_wrapper_class(options)
8787
classes = ["form-check"]
8888
classes << "form-check-inline" if layout_inline?(options[:inline])
89-
classes << "mb-3" unless options[:multiple] || %i[horizontal inline].include?(layout)
89+
classes << "mb-3" unless options[:multiple] ||
90+
%i[horizontal inline].include?(layout) ||
91+
options[:wrapper_class] == false ||
92+
options.dig(:wrapper, :class) == false
9093
classes << "form-switch" if options[:switch]
9194
classes << options.dig(:wrapper, :class).presence
9295
classes << options[:wrapper_class].presence

test/bootstrap_checkbox_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,20 @@ class BootstrapCheckboxTest < ActionView::TestCase
643643
assert_equivalent_html expected, @builder.check_box(:terms, label: "I agree to the terms", wrapper_class: "custom-class")
644644
end
645645

646+
test "check box with custom wrapper class false" do
647+
expected = <<~HTML
648+
<div class="form-check">
649+
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
650+
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
651+
<label class="form-check-label" for="user_terms">
652+
I agree to the terms
653+
</label>
654+
</div>
655+
HTML
656+
assert_equivalent_html expected, @builder.check_box(:terms, label: "I agree to the terms", wrapper_class: false)
657+
assert_equivalent_html expected, @builder.check_box(:terms, label: "I agree to the terms", wrapper: { class: false })
658+
end
659+
646660
test "inline check box with custom wrapper class" do
647661
expected = <<~HTML
648662
<div class="form-check form-check-inline mb-3 custom-class">

test/bootstrap_fields_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,28 @@ class BootstrapFieldsTest < ActionView::TestCase
245245
assert_equivalent_html expected, @builder.text_field(:email)
246246
end
247247

248+
test "text fields are wrapped correctly with wrapper_class and wrapper: { class: 'custom-class' }" do
249+
expected = <<~HTML
250+
<div class="custom-class">
251+
<label class="form-label required" for="user_email">Email</label>
252+
<input required="required" class="form-control" id="user_email" name="user[email]" type="text" value="[email protected]" />
253+
</div>
254+
HTML
255+
assert_equivalent_html expected, @builder.text_field(:email, wrapper_class: "custom-class")
256+
assert_equivalent_html expected, @builder.text_field(:email, wrapper: { class: "custom-class" })
257+
end
258+
259+
test "text fields are wrapped correctly with wrapper_class false" do
260+
expected = <<~HTML
261+
<div>
262+
<label class="form-label required" for="user_email">Email</label>
263+
<input required="required" class="form-control" id="user_email" name="user[email]" type="text" value="[email protected]" />
264+
</div>
265+
HTML
266+
assert_equivalent_html expected, @builder.text_field(:email, wrapper_class: false)
267+
assert_equivalent_html expected, @builder.text_field(:email, wrapper: { class: false })
268+
end
269+
248270
test "text fields are wrapped correctly when horizontal and gutter classes are given" do
249271
expected = <<~HTML
250272
<div class="mb-3 g-3">

test/bootstrap_radio_button_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,21 @@ class BootstrapRadioButtonTest < ActionView::TestCase
423423
@builder.radio_button(:misc, "1", label: "This is a radio button", wrapper_class: "custom-class")
424424
end
425425

426+
test "radio button with wrapper class false" do
427+
expected = <<~HTML
428+
<div class="form-check">
429+
<input class="form-check-input" id="user_misc_1" name="user[misc]" type="radio" value="1" />
430+
<label class="form-check-label" for="user_misc_1">
431+
This is a radio button
432+
</label>
433+
</div>
434+
HTML
435+
assert_equivalent_html expected,
436+
@builder.radio_button(:misc, "1", label: "This is a radio button", wrapper_class: false)
437+
assert_equivalent_html expected,
438+
@builder.radio_button(:misc, "1", label: "This is a radio button", wrapper: { class: false })
439+
end
440+
426441
test "inline radio button with custom wrapper class" do
427442
expected = <<~HTML
428443
<div class="form-check form-check-inline custom-class">

0 commit comments

Comments
 (0)