From 8cb137e64b00046e6736e1e136445f8df84703e8 Mon Sep 17 00:00:00 2001 From: Larry Reid Date: Sun, 28 Jan 2018 08:56:04 -0800 Subject: [PATCH 1/2] Inline checkboxes. --- lib/bootstrap_form/form_builder.rb | 14 +++----- test/bootstrap_checkbox_test.rb | 52 ++++++++++++++++++------------ 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index 60cebf7bc..2c3f178c1 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -136,19 +136,13 @@ def check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_ checkbox_html.concat(label(label_name, label_description, class: ["custom-control-label", label_class].compact.join(" "))) end else - if options[:inline] - label_class = " #{label_class}" if label_class + wrapper_class = "form-check" + wrapper_class += " form-check-inline" if options[:inline] + content_tag(:div, class: wrapper_class) do checkbox_html .concat(label(label_name, label_description, - { class: "form-check-inline#{label_class}" }.merge(options[:id].present? ? { for: options[:id] } : {}))) - else - content_tag(:div, class: "form-check") do - checkbox_html - .concat(label(label_name, - label_description, - { class: ["form-check-label", label_class].compact.join(" ") }.merge(options[:id].present? ? { for: options[:id] } : {}))) - end + { class: ["form-check-label", label_class].compact.join(" ") }.merge(options[:id].present? ? { for: options[:id] } : {}))) end end end diff --git a/test/bootstrap_checkbox_test.rb b/test/bootstrap_checkbox_test.rb index 74eabda9e..048621d36 100644 --- a/test/bootstrap_checkbox_test.rb +++ b/test/bootstrap_checkbox_test.rb @@ -98,33 +98,39 @@ class BootstrapCheckboxTest < ActionView::TestCase test "inline checkboxes" do expected = <<-HTML.strip_heredoc - - - +
+ + + +
HTML assert_equivalent_xml expected, @builder.check_box(:terms, label: 'I agree to the terms', inline: true) end test "disabled inline check_box" do expected = <<-HTML.strip_heredoc - - - +
+ + + +
HTML assert_equivalent_xml expected, @builder.check_box(:terms, label: 'I agree to the terms', inline: true, disabled: true) end test "inline checkboxes with custom label class" do expected = <<-HTML.strip_heredoc - - -