From 5aa27c2fa415d5aec3928ffd9e391095d466a4d5 Mon Sep 17 00:00:00 2001 From: Larry Reid Date: Fri, 16 Feb 2018 10:24:54 -0800 Subject: [PATCH 01/13] Test the combinations of layout at form and control level. --- test/bootstrap_form_test.rb | 321 +++++++++++++++++++++++++++++++++++- 1 file changed, 320 insertions(+), 1 deletion(-) diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index 0a930c22a..973acd4bf 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -14,6 +14,102 @@ class BootstrapFormTest < ActionView::TestCase assert_equivalent_xml expected, bootstrap_form_for(@user) { |f| nil } end + test "default-style form fields layout horizontal" do + expected = <<-HTML.strip_heredoc +
+ +
+ +
+ +
+
+
+ + + +
+
+ +
+
+ + +
+
+ + +
+
+
+
+ +
+ +
+
+
+ HTML + + collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] + actual = bootstrap_form_for(@user) do |f| + f.email_field(:email, layout: :horizontal) + .concat(f.check_box(:terms, label: 'I agree to the terms', layout: :horizontal)) + .concat(f.collection_radio_buttons(:misc, collection, :id, :street, layout: :horizontal)) + .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :horizontal)) + end + + assert_equivalent_xml expected, actual + end + + test "default-style form fields layout inline" do + expected = <<-HTML.strip_heredoc +
+ +
+ + +
+
+ + + +
+
+ +
+ + +
+
+ + +
+
+
+ + +
+
+ HTML + + collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] + actual = bootstrap_form_for(@user) do |f| + f.email_field(:email, layout: :inline) + .concat(f.check_box(:terms, label: 'I agree to the terms', layout: :inline)) + .concat(f.collection_radio_buttons(:misc, collection, :id, :street, layout: :inline)) + .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :inline)) + end + + assert_equivalent_xml expected, actual + end + if ::Rails::VERSION::STRING >= '5.1' # No need to test 5.2 separately for this case, since 5.2 does *not* # generate a default ID for the form element. @@ -36,6 +132,103 @@ class BootstrapFormTest < ActionView::TestCase assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :inline) { |f| nil } end + test "inline-style form fields layout horizontal" do + expected = <<-HTML.strip_heredoc +
+ +
+ +
+ +
+
+
+ + + +
+ +
+ +
+
+ + +
+
+ + +
+
+
+
+ +
+ +
+
+
+ HTML + + collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] + actual = bootstrap_form_for(@user, layout: :inline) do |f| + f.email_field(:email, layout: :horizontal) + .concat(f.check_box(:terms, label: 'I agree to the terms', layout: :horizontal)) + .concat(f.collection_check_boxes(:misc, collection, :id, :street, layout: :horizontal)) + .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :horizontal)) + end + + assert_equivalent_xml expected, actual + end + + test "inline-style form fields layout default" do + expected = <<-HTML.strip_heredoc +
+ +
+ + +
+
+ + + +
+
+ +
+ + +
+
+ + +
+
+
+ + +
+
+ HTML + + collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] + actual = bootstrap_form_for(@user, layout: :inline) do |f| + f.email_field(:email, layout: :default) + .concat(f.check_box(:terms, label: 'I agree to the terms', layout: :default)) + .concat(f.collection_radio_buttons(:misc, collection, :id, :street, layout: :default)) + .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :default)) + end + + assert_equivalent_xml expected, actual + end + test "horizontal-style forms" do expected = <<-HTML.strip_heredoc
@@ -46,9 +239,135 @@ class BootstrapFormTest < ActionView::TestCase +
+ + + +
+
+ +
+
+ + +
+
+ + +
+
+
+
+ +
+ +
+
+
+ HTML + + collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] + actual = bootstrap_form_for(@user, layout: :horizontal) do |f| + f.email_field(:email) + .concat(f.check_box(:terms, label: 'I agree to the terms')) + .concat(f.collection_radio_buttons(:misc, collection, :id, :street)) + .concat(f.select(:status, [['activated', 1], ['blocked', 2]])) + end + + assert_equivalent_xml expected, actual + end + + test "horizontal-style form fields layout default" do + expected = <<-HTML.strip_heredoc +
+ +
+ + +
+
+ + + +
+
+ +
+ + +
+
+ + +
+
+
+ + +
+
+ HTML + + collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] + actual = bootstrap_form_for(@user, layout: :horizontal) do |f| + f.email_field(:email, layout: :default) + .concat(f.check_box(:terms, label: 'I agree to the terms', layout: :default)) + .concat(f.collection_radio_buttons(:misc, collection, :id, :street, layout: :default)) + .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :default)) + end + + assert_equivalent_xml expected, actual + end + + test "horizontal-style form fields layout inline" do + expected = <<-HTML.strip_heredoc +
+ +
+ + +
+
+ + + +
+
+ +
+ + +
+
+ + +
+
+
+ + +
HTML - assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email } + + collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] + actual = bootstrap_form_for(@user, layout: :horizontal) do |f| + f.email_field(:email, layout: :inline) + .concat(f.check_box(:terms, label: 'I agree to the terms', layout: :inline)) + .concat(f.collection_radio_buttons(:misc, collection, :id, :street, layout: :inline)) + .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :inline)) + end + + assert_equivalent_xml expected, actual end test "existing styles aren't clobbered when specifying a form style" do From 8a3161453f7df494de91100bcbf364e17ba7596a Mon Sep 17 00:00:00 2001 From: Larry Reid Date: Fri, 16 Feb 2018 10:29:29 -0800 Subject: [PATCH 02/13] Strip layout from options for check boxes and radios. --- lib/bootstrap_form/form_builder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index bcc70c66d..9ec17dca1 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -105,7 +105,7 @@ def time_zone_select_with_bootstrap(method, priority_zones = nil, options = {}, def check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_value = "0", &block) options = options.symbolize_keys! - check_box_options = options.except(:label, :label_class, :help, :inline, :custom, :hide_label, :skip_label) + check_box_options = options.except(:label, :label_class, :help, :inline, :custom, :hide_label, :layout, :skip_label) check_box_classes = [check_box_options[:class]] check_box_classes << "position-static" if options[:skip_label] || options[:hide_label] if options[:custom] @@ -165,7 +165,7 @@ def check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_ def radio_button_with_bootstrap(name, value, *args) options = args.extract_options!.symbolize_keys! - radio_options = options.except(:label, :label_class, :help, :inline, :custom, :hide_label, :skip_label) + radio_options = options.except(:label, :label_class, :help, :inline, :custom, :hide_label, :layout, :skip_label) radio_classes = [options[:class]] radio_classes << "position-static" if options[:skip_label] || options[:hide_label] if options[:custom] From a50f15f28dc0ce1a4127663a05c8ba44716587fc Mon Sep 17 00:00:00 2001 From: Larry Reid Date: Fri, 16 Feb 2018 13:09:45 -0800 Subject: [PATCH 03/13] Improve the tests. --- test/bootstrap_form_test.rb | 69 ++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 13 deletions(-) diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index 973acd4bf..50382d389 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -57,12 +57,13 @@ class BootstrapFormTest < ActionView::TestCase collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] actual = bootstrap_form_for(@user) do |f| f.email_field(:email, layout: :horizontal) - .concat(f.check_box(:terms, label: 'I agree to the terms', layout: :horizontal)) + .concat(f.check_box(:terms, label: 'I agree to the terms')) .concat(f.collection_radio_buttons(:misc, collection, :id, :street, layout: :horizontal)) .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :horizontal)) end assert_equivalent_xml expected, actual + # See the rendered output at: https://www.bootply.com/S2WFzEYChf end test "default-style form fields layout inline" do @@ -70,7 +71,7 @@ class BootstrapFormTest < ActionView::TestCase
- +
@@ -79,7 +80,7 @@ class BootstrapFormTest < ActionView::TestCase
- +
@@ -90,7 +91,7 @@ class BootstrapFormTest < ActionView::TestCase
- + +
+ + +
+
+ + + +
+
+ +
+ + +
+
+ + +
+
+
+ + +
HTML - assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :inline) { |f| nil } + + collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] + actual = bootstrap_form_for(@user, layout: :inline) do |f| + f.email_field(:email) + .concat(f.check_box(:terms, label: 'I agree to the terms')) + .concat(f.collection_radio_buttons(:misc, collection, :id, :street)) + .concat(f.select(:status, [['activated', 1], ['blocked', 2]])) + end + + assert_equivalent_xml expected, actual end test "inline-style form fields layout horizontal" do @@ -176,14 +216,16 @@ class BootstrapFormTest < ActionView::TestCase collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] actual = bootstrap_form_for(@user, layout: :inline) do |f| f.email_field(:email, layout: :horizontal) - .concat(f.check_box(:terms, label: 'I agree to the terms', layout: :horizontal)) + .concat(f.check_box(:terms, label: 'I agree to the terms')) .concat(f.collection_check_boxes(:misc, collection, :id, :street, layout: :horizontal)) .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :horizontal)) end assert_equivalent_xml expected, actual + # See the rendered output at: https://www.bootply.com/1hMYpBHds5 end + # FIXME: The following does *not* render as a default layout form. test "inline-style form fields layout default" do expected = <<-HTML.strip_heredoc
@@ -221,12 +263,13 @@ class BootstrapFormTest < ActionView::TestCase collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] actual = bootstrap_form_for(@user, layout: :inline) do |f| f.email_field(:email, layout: :default) - .concat(f.check_box(:terms, label: 'I agree to the terms', layout: :default)) + .concat(f.check_box(:terms, label: 'I agree to the terms')) .concat(f.collection_radio_buttons(:misc, collection, :id, :street, layout: :default)) .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :default)) end assert_equivalent_xml expected, actual + # See the rendered output at: https://www.bootply.com/JqdpfgA36j end test "horizontal-style forms" do @@ -317,7 +360,7 @@ class BootstrapFormTest < ActionView::TestCase collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] actual = bootstrap_form_for(@user, layout: :horizontal) do |f| f.email_field(:email, layout: :default) - .concat(f.check_box(:terms, label: 'I agree to the terms', layout: :default)) + .concat(f.check_box(:terms, label: 'I agree to the terms')) .concat(f.collection_radio_buttons(:misc, collection, :id, :street, layout: :default)) .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :default)) end @@ -330,7 +373,7 @@ class BootstrapFormTest < ActionView::TestCase
- +
@@ -339,7 +382,7 @@ class BootstrapFormTest < ActionView::TestCase
- +
@@ -350,7 +393,7 @@ class BootstrapFormTest < ActionView::TestCase
- +
- +
diff --git a/test/bootstrap_form_group_test.rb b/test/bootstrap_form_group_test.rb index 9f0714802..f82a25518 100644 --- a/test/bootstrap_form_group_test.rb +++ b/test/bootstrap_form_group_test.rb @@ -459,7 +459,7 @@ class BootstrapFormGroupTest < ActionView::TestCase
- +
From c77b1cf1fe8f31ac858261e2507315a1de010f0b Mon Sep 17 00:00:00 2001 From: Larry Reid Date: Fri, 16 Feb 2018 16:55:33 -0800 Subject: [PATCH 05/13] All but custom. Need to check/update all the Bootply rendered versions. --- lib/bootstrap_form/form_builder.rb | 42 +++++++++++++++++++++++------- test/bootstrap_form_group_test.rb | 2 +- test/bootstrap_form_test.rb | 12 +++++---- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index 9ec17dca1..b5d0204b2 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -105,7 +105,7 @@ def time_zone_select_with_bootstrap(method, priority_zones = nil, options = {}, def check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_value = "0", &block) options = options.symbolize_keys! - check_box_options = options.except(:label, :label_class, :help, :inline, :custom, :hide_label, :layout, :skip_label) + check_box_options = options.except(:label, :label_class, :help, :inline, :custom, :hide_label, :skip_label) check_box_classes = [check_box_options[:class]] check_box_classes << "position-static" if options[:skip_label] || options[:hide_label] if options[:custom] @@ -134,7 +134,7 @@ def check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_ if options[:custom] div_class = ["custom-control", "custom-checkbox"] - div_class.append("custom-control-inline") if options[:inline] + div_class.append("custom-control-inline") if layout_inline?(options[:inline]) label_class = label_classes.prepend("custom-control-label").compact.join(" ") content_tag(:div, class: div_class.compact.join(" ")) do if options[:skip_label] @@ -146,7 +146,7 @@ def check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_ end else wrapper_class = "form-check" - wrapper_class += " form-check-inline" if options[:inline] + wrapper_class += " form-check-inline" if layout_inline?(options[:inline]) label_class = label_classes.prepend("form-check-label").compact.join(" ") content_tag(:div, class: wrapper_class) do if options[:skip_label] @@ -165,7 +165,7 @@ def check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_ def radio_button_with_bootstrap(name, value, *args) options = args.extract_options!.symbolize_keys! - radio_options = options.except(:label, :label_class, :help, :inline, :custom, :hide_label, :layout, :skip_label) + radio_options = options.except(:label, :label_class, :help, :inline, :custom, :hide_label, :skip_label) radio_classes = [options[:class]] radio_classes << "position-static" if options[:skip_label] || options[:hide_label] if options[:custom] @@ -182,7 +182,7 @@ def radio_button_with_bootstrap(name, value, *args) if options[:custom] div_class = ["custom-control", "custom-radio"] - div_class.append("custom-control-inline") if options[:inline] + div_class.append("custom-control-inline") if layout_inline?(options[:inline]) label_class = label_classes.prepend("custom-control-label").compact.join(" ") content_tag(:div, class: div_class.compact.join(" ")) do if options[:skip_label] @@ -194,7 +194,7 @@ def radio_button_with_bootstrap(name, value, *args) end else wrapper_class = "form-check" - wrapper_class += " form-check-inline" if options[:inline] + wrapper_class += " form-check-inline" if layout_inline?(options[:inline]) label_class = label_classes.prepend("form-check-label").compact.join(" ") content_tag(:div, class: "#{wrapper_class}#{disabled_class}") do if options[:skip_label] @@ -233,6 +233,7 @@ def form_group(*args, &block) options[:class] = ["form-group", options[:class]].compact.join(' ') options[:class] << " row" if get_group_layout(options[:layout]) == :horizontal + options[:class] << " form-inline" if field_inline_override?(options[:layout]) options[:class] << " #{feedback_class}" if options[:icon] content_tag(:div, options.except(:id, :label, :help, :icon, :label_col, :control_col, :layout)) do @@ -274,8 +275,28 @@ def fields_for_with_bootstrap(record_name, record_object = nil, fields_options = private - def horizontal? - layout == :horizontal + def layout_default?(field_layout = nil) + [:default, nil].include? layout_in_effect(field_layout) + end + + def layout_horizontal?(field_layout = nil) + layout_in_effect(field_layout) == :horizontal + end + + def layout_inline?(field_layout = nil) + layout_in_effect(field_layout) == :inline + end + + def field_inline_override?(field_layout = nil) + field_layout == :inline && layout != :inline + end + + # true and false should only come from check_box and radio_button, + # and those don't have a :horizontal layout + def layout_in_effect(field_layout) + field_layout = :inline if field_layout == true + field_layout = :default if field_layout == false + field_layout || layout end def get_group_layout(group_layout) @@ -411,9 +432,11 @@ def generate_label(id, name, options, custom_label_col, group_layout) options[:for] = id if acts_like_form_tag classes = [options[:class]] - if get_group_layout(group_layout) == :horizontal + if layout_horizontal?(group_layout) classes << "col-form-label" classes << (custom_label_col || label_col) + elsif layout_inline?(group_layout) + classes.append(["mb-2", "mr-sm-2"]) end unless options.delete(:skip_required) @@ -452,6 +475,7 @@ def get_error_messages(name) end def inputs_collection(name, collection, value, text, options = {}, &block) + options[:inline] ||= layout_inline?(options[:layout]) form_group_builder(name, options) do inputs = "" diff --git a/test/bootstrap_form_group_test.rb b/test/bootstrap_form_group_test.rb index f82a25518..74dbaee4e 100644 --- a/test/bootstrap_form_group_test.rb +++ b/test/bootstrap_form_group_test.rb @@ -458,7 +458,7 @@ class BootstrapFormGroupTest < ActionView::TestCase expected = <<-HTML.strip_heredoc
-
+
diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index 50382d389..dab991ba0 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -79,7 +79,7 @@ class BootstrapFormTest < ActionView::TestCase
-
+
@@ -109,9 +109,10 @@ class BootstrapFormTest < ActionView::TestCase end assert_equivalent_xml expected, actual - # See the rendered output at: https://www.bootply.com/WvdETgDeyZ + # See the rendered output at: https://www.bootply.com/bnIIcSOOMq # Note that the baseline of the label text to the left of the two radio buttons # isn't aligned with the text of the radio button labels. + # TODO: Align baseline better. end if ::Rails::VERSION::STRING >= '5.1' @@ -172,6 +173,7 @@ class BootstrapFormTest < ActionView::TestCase assert_equivalent_xml expected, actual end + # FIXME: The following does *not* render as a horizontal layout form. test "inline-style form fields layout horizontal" do expected = <<-HTML.strip_heredoc @@ -216,7 +218,7 @@ class BootstrapFormTest < ActionView::TestCase collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] actual = bootstrap_form_for(@user, layout: :inline) do |f| f.email_field(:email, layout: :horizontal) - .concat(f.check_box(:terms, label: 'I agree to the terms')) + .concat(f.check_box(:terms, label: 'I agree to the terms', inline: false)) .concat(f.collection_check_boxes(:misc, collection, :id, :street, layout: :horizontal)) .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :horizontal)) end @@ -263,7 +265,7 @@ class BootstrapFormTest < ActionView::TestCase collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] actual = bootstrap_form_for(@user, layout: :inline) do |f| f.email_field(:email, layout: :default) - .concat(f.check_box(:terms, label: 'I agree to the terms')) + .concat(f.check_box(:terms, label: 'I agree to the terms', inline: false)) .concat(f.collection_radio_buttons(:misc, collection, :id, :street, layout: :default)) .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :default)) end @@ -381,7 +383,7 @@ class BootstrapFormTest < ActionView::TestCase
-
+
From 08b695c703f56e5061185352b02a1561dfbf0861 Mon Sep 17 00:00:00 2001 From: Larry Reid Date: Sat, 17 Feb 2018 08:11:59 -0800 Subject: [PATCH 06/13] Tweak label classes for visual rendering. --- lib/bootstrap_form/form_builder.rb | 2 +- test/bootstrap_fields_test.rb | 2 +- test/bootstrap_form_group_test.rb | 2 +- test/bootstrap_form_test.rb | 24 ++++++++++++------------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index b5d0204b2..81470463c 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -436,7 +436,7 @@ def generate_label(id, name, options, custom_label_col, group_layout) classes << "col-form-label" classes << (custom_label_col || label_col) elsif layout_inline?(group_layout) - classes.append(["mb-2", "mr-sm-2"]) + classes << "mr-sm-2" end unless options.delete(:skip_required) diff --git a/test/bootstrap_fields_test.rb b/test/bootstrap_fields_test.rb index acb2f76d8..2e39aca67 100644 --- a/test/bootstrap_fields_test.rb +++ b/test/bootstrap_fields_test.rb @@ -310,7 +310,7 @@ class BootstrapFieldsTest < ActionView::TestCase
- +
diff --git a/test/bootstrap_form_group_test.rb b/test/bootstrap_form_group_test.rb index 74dbaee4e..2789dd957 100644 --- a/test/bootstrap_form_group_test.rb +++ b/test/bootstrap_form_group_test.rb @@ -459,7 +459,7 @@ class BootstrapFormGroupTest < ActionView::TestCase
- +
diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index dab991ba0..925b07dd7 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -71,7 +71,7 @@ class BootstrapFormTest < ActionView::TestCase
- +
@@ -80,7 +80,7 @@ class BootstrapFormTest < ActionView::TestCase
- +
@@ -91,7 +91,7 @@ class BootstrapFormTest < ActionView::TestCase
- +
- +
@@ -142,7 +142,7 @@ class BootstrapFormTest < ActionView::TestCase
- +
@@ -153,7 +153,7 @@ class BootstrapFormTest < ActionView::TestCase
- +
- +
@@ -384,7 +384,7 @@ class BootstrapFormTest < ActionView::TestCase
- +
@@ -395,7 +395,7 @@ class BootstrapFormTest < ActionView::TestCase
- + +
+ +
+ +
+
+
+ + + +
+ +
+ +
+
+ + +
+
+ + +
+
+
+
+ +
+ +
+
+ + HTML + + collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] + actual = bootstrap_form_for(@user, layout: :inline) do |f| + f.email_field(:email, layout: :horizontal) + .concat(f.check_box(:terms, label: 'I agree to the terms', layout: :horizontal)) + .concat(f.collection_check_boxes(:misc, collection, :id, :street, layout: :horizontal)) + .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :horizontal)) + end + + assert_equivalent_xml expected, actual + end + + test "inline-style form fields layout default" do + expected = <<-HTML.strip_heredoc +
+ +
+ + +
+
+ + + +
+
+ +
+ + +
+
+ + +
+
+
+ + +
+
+ HTML + + collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] + actual = bootstrap_form_for(@user, layout: :inline) do |f| + f.email_field(:email, layout: :default) + .concat(f.check_box(:terms, label: 'I agree to the terms', layout: :default)) + .concat(f.collection_radio_buttons(:misc, collection, :id, :street, layout: :default)) + .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :default)) + end + + assert_equivalent_xml expected, actual + end + test "horizontal-style forms" do expected = <<-HTML.strip_heredoc
From 4fe6bd4cbfe63970e995e35dd76bf56f0cd068c5 Mon Sep 17 00:00:00 2001 From: Larry Reid Date: Fri, 16 Feb 2018 10:29:29 -0800 Subject: [PATCH 08/13] Strip layout from options for check boxes and radios. --- lib/bootstrap_form/form_builder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index 81470463c..7eec68d2e 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -105,7 +105,7 @@ def time_zone_select_with_bootstrap(method, priority_zones = nil, options = {}, def check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_value = "0", &block) options = options.symbolize_keys! - check_box_options = options.except(:label, :label_class, :help, :inline, :custom, :hide_label, :skip_label) + check_box_options = options.except(:label, :label_class, :help, :inline, :custom, :hide_label, :layout, :skip_label) check_box_classes = [check_box_options[:class]] check_box_classes << "position-static" if options[:skip_label] || options[:hide_label] if options[:custom] @@ -165,7 +165,7 @@ def check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_ def radio_button_with_bootstrap(name, value, *args) options = args.extract_options!.symbolize_keys! - radio_options = options.except(:label, :label_class, :help, :inline, :custom, :hide_label, :skip_label) + radio_options = options.except(:label, :label_class, :help, :inline, :custom, :hide_label, :layout, :skip_label) radio_classes = [options[:class]] radio_classes << "position-static" if options[:skip_label] || options[:hide_label] if options[:custom] From 2abfec372499b968f5b2da112cca1f23fca85675 Mon Sep 17 00:00:00 2001 From: Larry Reid Date: Fri, 16 Feb 2018 13:09:45 -0800 Subject: [PATCH 09/13] Improve the tests. --- test/bootstrap_form_test.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index d742a6884..259d92615 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -318,14 +318,16 @@ class BootstrapFormTest < ActionView::TestCase collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] actual = bootstrap_form_for(@user, layout: :inline) do |f| f.email_field(:email, layout: :horizontal) - .concat(f.check_box(:terms, label: 'I agree to the terms', layout: :horizontal)) + .concat(f.check_box(:terms, label: 'I agree to the terms')) .concat(f.collection_check_boxes(:misc, collection, :id, :street, layout: :horizontal)) .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :horizontal)) end assert_equivalent_xml expected, actual + # See the rendered output at: https://www.bootply.com/1hMYpBHds5 end + # FIXME: The following does *not* render as a default layout form. test "inline-style form fields layout default" do expected = <<-HTML.strip_heredoc @@ -363,12 +365,13 @@ class BootstrapFormTest < ActionView::TestCase collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] actual = bootstrap_form_for(@user, layout: :inline) do |f| f.email_field(:email, layout: :default) - .concat(f.check_box(:terms, label: 'I agree to the terms', layout: :default)) + .concat(f.check_box(:terms, label: 'I agree to the terms')) .concat(f.collection_radio_buttons(:misc, collection, :id, :street, layout: :default)) .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :default)) end assert_equivalent_xml expected, actual + # See the rendered output at: https://www.bootply.com/JqdpfgA36j end test "horizontal-style forms" do From c9f47e920354913b834e228bd0ebbfb8b03741a5 Mon Sep 17 00:00:00 2001 From: Larry Reid Date: Fri, 16 Feb 2018 16:55:33 -0800 Subject: [PATCH 10/13] All but custom. Need to check/update all the Bootply rendered versions. --- lib/bootstrap_form/form_builder.rb | 4 ++-- test/bootstrap_form_test.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index 7eec68d2e..81470463c 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -105,7 +105,7 @@ def time_zone_select_with_bootstrap(method, priority_zones = nil, options = {}, def check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_value = "0", &block) options = options.symbolize_keys! - check_box_options = options.except(:label, :label_class, :help, :inline, :custom, :hide_label, :layout, :skip_label) + check_box_options = options.except(:label, :label_class, :help, :inline, :custom, :hide_label, :skip_label) check_box_classes = [check_box_options[:class]] check_box_classes << "position-static" if options[:skip_label] || options[:hide_label] if options[:custom] @@ -165,7 +165,7 @@ def check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_ def radio_button_with_bootstrap(name, value, *args) options = args.extract_options!.symbolize_keys! - radio_options = options.except(:label, :label_class, :help, :inline, :custom, :hide_label, :layout, :skip_label) + radio_options = options.except(:label, :label_class, :help, :inline, :custom, :hide_label, :skip_label) radio_classes = [options[:class]] radio_classes << "position-static" if options[:skip_label] || options[:hide_label] if options[:custom] diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index 259d92615..778c86443 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -318,7 +318,7 @@ class BootstrapFormTest < ActionView::TestCase collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] actual = bootstrap_form_for(@user, layout: :inline) do |f| f.email_field(:email, layout: :horizontal) - .concat(f.check_box(:terms, label: 'I agree to the terms')) + .concat(f.check_box(:terms, label: 'I agree to the terms', inline: false)) .concat(f.collection_check_boxes(:misc, collection, :id, :street, layout: :horizontal)) .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :horizontal)) end @@ -365,7 +365,7 @@ class BootstrapFormTest < ActionView::TestCase collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] actual = bootstrap_form_for(@user, layout: :inline) do |f| f.email_field(:email, layout: :default) - .concat(f.check_box(:terms, label: 'I agree to the terms')) + .concat(f.check_box(:terms, label: 'I agree to the terms', inline: false)) .concat(f.collection_radio_buttons(:misc, collection, :id, :street, layout: :default)) .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :default)) end From a1b4e0683939fa79d79edc79f50417114153f507 Mon Sep 17 00:00:00 2001 From: Larry Reid Date: Sat, 17 Feb 2018 08:11:59 -0800 Subject: [PATCH 11/13] Tweak label classes for visual rendering. --- test/bootstrap_form_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index 778c86443..282ef2bd2 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -327,7 +327,7 @@ class BootstrapFormTest < ActionView::TestCase # See the rendered output at: https://www.bootply.com/1hMYpBHds5 end - # FIXME: The following does *not* render as a default layout form. + # NOTE: The following does *not* render as a default layout form. test "inline-style form fields layout default" do expected = <<-HTML.strip_heredoc From c64fa5c1b750d66d71940df6520fbb781c8b18c9 Mon Sep 17 00:00:00 2001 From: Larry Reid Date: Wed, 21 Feb 2018 12:33:04 -0800 Subject: [PATCH 12/13] Remove incorrect tests. --- test/bootstrap_form_test.rb | 201 ------------------------------------ 1 file changed, 201 deletions(-) diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index 282ef2bd2..9c8cca7df 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -173,207 +173,6 @@ class BootstrapFormTest < ActionView::TestCase assert_equivalent_xml expected, actual end - # NOTE: The following does *not* render as a horizontal layout form. - test "inline-style form fields layout horizontal" do - expected = <<-HTML.strip_heredoc - - -
- -
- -
-
-
- - - -
- -
- -
-
- - -
-
- - -
-
-
-
- -
- -
-
- - HTML - - collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - actual = bootstrap_form_for(@user, layout: :inline) do |f| - f.email_field(:email, layout: :horizontal) - .concat(f.check_box(:terms, label: 'I agree to the terms', inline: false)) - .concat(f.collection_check_boxes(:misc, collection, :id, :street, layout: :horizontal)) - .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :horizontal)) - end - - assert_equivalent_xml expected, actual - # See the rendered output at: https://www.bootply.com/1hMYpBHds5 - end - - # NOTE: The following does *not* render as a default layout form. - test "inline-style form fields layout default" do - expected = <<-HTML.strip_heredoc -
- -
- - -
-
- - - -
-
- -
- - -
-
- - -
-
-
- - -
-
- HTML - - collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - actual = bootstrap_form_for(@user, layout: :inline) do |f| - f.email_field(:email, layout: :default) - .concat(f.check_box(:terms, label: 'I agree to the terms', inline: false)) - .concat(f.collection_radio_buttons(:misc, collection, :id, :street, layout: :default)) - .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :default)) - end - - assert_equivalent_xml expected, actual - # See the rendered output at: https://www.bootply.com/JqdpfgA36j - end - - test "inline-style form fields layout horizontal" do - expected = <<-HTML.strip_heredoc -
- -
- -
- -
-
-
- - - -
- -
- -
-
- - -
-
- - -
-
-
-
- -
- -
-
-
- HTML - - collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - actual = bootstrap_form_for(@user, layout: :inline) do |f| - f.email_field(:email, layout: :horizontal) - .concat(f.check_box(:terms, label: 'I agree to the terms', inline: false)) - .concat(f.collection_check_boxes(:misc, collection, :id, :street, layout: :horizontal)) - .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :horizontal)) - end - - assert_equivalent_xml expected, actual - # See the rendered output at: https://www.bootply.com/1hMYpBHds5 - end - - # NOTE: The following does *not* render as a default layout form. - test "inline-style form fields layout default" do - expected = <<-HTML.strip_heredoc -
- -
- - -
-
- - - -
-
- -
- - -
-
- - -
-
-
- - -
-
- HTML - - collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - actual = bootstrap_form_for(@user, layout: :inline) do |f| - f.email_field(:email, layout: :default) - .concat(f.check_box(:terms, label: 'I agree to the terms', inline: false)) - .concat(f.collection_radio_buttons(:misc, collection, :id, :street, layout: :default)) - .concat(f.select(:status, [['activated', 1], ['blocked', 2]], layout: :default)) - end - - assert_equivalent_xml expected, actual - # See the rendered output at: https://www.bootply.com/JqdpfgA36j - end - test "horizontal-style forms" do expected = <<-HTML.strip_heredoc
From 0507950b3f57559ad810c4d64afe1a4922cc0385 Mon Sep 17 00:00:00 2001 From: Larry Reid Date: Wed, 21 Feb 2018 12:49:57 -0800 Subject: [PATCH 13/13] Check rendering and add links to Bootply. --- test/bootstrap_form_test.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index 9c8cca7df..5e15c7584 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -267,6 +267,7 @@ class BootstrapFormTest < ActionView::TestCase end assert_equivalent_xml expected, actual + # See the rendered output at: https://www.bootply.com/4f23be1nLn end test "horizontal-style form fields layout inline" do @@ -312,6 +313,7 @@ class BootstrapFormTest < ActionView::TestCase end assert_equivalent_xml expected, actual + # See the rendered output here: https://www.bootply.com/Qby9FC9d3u# end test "existing styles aren't clobbered when specifying a form style" do