From 3a77ef5212dfb98c0bf30a9b54d19df88d2983b8 Mon Sep 17 00:00:00 2001 From: Dieter Lunn Date: Fri, 29 Jan 2021 11:11:17 -0600 Subject: [PATCH 01/12] feat: add support for floating text fields in Bootstrap 5 --- lib/comfy_bootstrap_form/form_builder.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/comfy_bootstrap_form/form_builder.rb b/lib/comfy_bootstrap_form/form_builder.rb index d0bec68..156540c 100644 --- a/lib/comfy_bootstrap_form/form_builder.rb +++ b/lib/comfy_bootstrap_form/form_builder.rb @@ -122,7 +122,8 @@ def file_field(method, options = {}) draw_form_group(bootstrap, method, options) do if bootstrap.custom_control - content_tag(:div, class: "custom-file") do + content_tag(:div, class: "custom-file") do form_group_class += " form-floating" if bootstrap.floating? + add_css_class!(options, "custom-file-input") remove_css_class!(options, "form-control") label_text = options.delete(:placeholder) @@ -379,12 +380,18 @@ def draw_form_group(bootstrap, method, options) end form_group_class = "form-group" - form_group_class += " row" if bootstrap.horizontal? - form_group_class += " mr-sm-2" if bootstrap.inline? + form_group_class += " row" if bootstrap.horizontal? + form_group_class += " mr-sm-2" if bootstrap.inline? + form_group_class += " form-floating" if bootstrap.floating? content_tag(:div, class: form_group_class) do - concat label - concat control + unless bootstrap.floating? + concat label + concat control + else + concat control + concat label + end end end From 3871d60f388060488a753ba915e8409839279439 Mon Sep 17 00:00:00 2001 From: Dieter Lunn Date: Fri, 29 Jan 2021 11:13:56 -0600 Subject: [PATCH 02/12] chore: update version --- lib/comfy_bootstrap_form/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/comfy_bootstrap_form/version.rb b/lib/comfy_bootstrap_form/version.rb index 757bf54..69bd782 100644 --- a/lib/comfy_bootstrap_form/version.rb +++ b/lib/comfy_bootstrap_form/version.rb @@ -2,6 +2,6 @@ module ComfyBootstrapForm - VERSION = "4.0.9" + VERSION = "4.0.10" end From 7cf414f1d05c9c3a407c4c355863cb033726a0f4 Mon Sep 17 00:00:00 2001 From: Dieter Lunn Date: Fri, 29 Jan 2021 11:16:56 -0600 Subject: [PATCH 03/12] feat: add floating option --- lib/comfy_bootstrap_form/bootstrap_options.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/comfy_bootstrap_form/bootstrap_options.rb b/lib/comfy_bootstrap_form/bootstrap_options.rb index 057421f..65084e4 100644 --- a/lib/comfy_bootstrap_form/bootstrap_options.rb +++ b/lib/comfy_bootstrap_form/bootstrap_options.rb @@ -74,6 +74,9 @@ class BootstrapOptions # form.text_field :foo, bootstrap: {error: "Error Message"} # attr_accessor :error + + # Use Bootstrap 5 floating labels + attr_accessor :floating def initialize(options = {}) set_defaults @@ -133,6 +136,7 @@ def set_defaults @error = nil @check_inline = false @custom_control = true + @floating = false end end From 0063cad60a2043d40cc5fbe3bd2073765916a476 Mon Sep 17 00:00:00 2001 From: Dieter Lunn Date: Fri, 29 Jan 2021 11:21:35 -0600 Subject: [PATCH 04/12] fix: add floating boolean check method --- lib/comfy_bootstrap_form/bootstrap_options.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/comfy_bootstrap_form/bootstrap_options.rb b/lib/comfy_bootstrap_form/bootstrap_options.rb index 65084e4..fcdfd36 100644 --- a/lib/comfy_bootstrap_form/bootstrap_options.rb +++ b/lib/comfy_bootstrap_form/bootstrap_options.rb @@ -90,6 +90,10 @@ def horizontal? def inline? @layout.to_s == "inline" end + + def floating? + floating + end def offset_col_class label_col_class.gsub(%r{col-(\w+)-(\d+)}, 'offset-\1-\2') From 7d158521b4a5ab917c44d625c59abf2838eea1dc Mon Sep 17 00:00:00 2001 From: Dieter Lunn Date: Fri, 29 Jan 2021 11:21:54 -0600 Subject: [PATCH 05/12] chore: bump version for fix --- lib/comfy_bootstrap_form/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/comfy_bootstrap_form/version.rb b/lib/comfy_bootstrap_form/version.rb index 69bd782..2fbefb3 100644 --- a/lib/comfy_bootstrap_form/version.rb +++ b/lib/comfy_bootstrap_form/version.rb @@ -2,6 +2,6 @@ module ComfyBootstrapForm - VERSION = "4.0.10" + VERSION = "4.0.11" end From 29e863fa17be6e456797d3db080e652dbf5252e9 Mon Sep 17 00:00:00 2001 From: Dieter Lunn Date: Fri, 29 Jan 2021 12:06:31 -0600 Subject: [PATCH 06/12] fix: defaulting custom_control to false as it breaks default behaviour --- lib/comfy_bootstrap_form/bootstrap_options.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/comfy_bootstrap_form/bootstrap_options.rb b/lib/comfy_bootstrap_form/bootstrap_options.rb index fcdfd36..54481df 100644 --- a/lib/comfy_bootstrap_form/bootstrap_options.rb +++ b/lib/comfy_bootstrap_form/bootstrap_options.rb @@ -90,10 +90,6 @@ def horizontal? def inline? @layout.to_s == "inline" end - - def floating? - floating - end def offset_col_class label_col_class.gsub(%r{col-(\w+)-(\d+)}, 'offset-\1-\2') @@ -139,7 +135,7 @@ def set_defaults @help = nil @error = nil @check_inline = false - @custom_control = true + @custom_control = false @floating = false end From d66f9e2cb6b57b54699869639fe8e03b6bc1c13b Mon Sep 17 00:00:00 2001 From: Dieter Lunn Date: Fri, 29 Jan 2021 12:10:02 -0600 Subject: [PATCH 07/12] fix: use if instead of unless --- lib/comfy_bootstrap_form/form_builder.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/comfy_bootstrap_form/form_builder.rb b/lib/comfy_bootstrap_form/form_builder.rb index 156540c..bf0b89f 100644 --- a/lib/comfy_bootstrap_form/form_builder.rb +++ b/lib/comfy_bootstrap_form/form_builder.rb @@ -382,15 +382,15 @@ def draw_form_group(bootstrap, method, options) form_group_class = "form-group" form_group_class += " row" if bootstrap.horizontal? form_group_class += " mr-sm-2" if bootstrap.inline? - form_group_class += " form-floating" if bootstrap.floating? + form_group_class += " form-floating mb-2" if bootstrap.floating content_tag(:div, class: form_group_class) do - unless bootstrap.floating? - concat label + if bootstrap.floating concat control + concat label else - concat control concat label + concat control end end end From 3fae79f1837eb371a53093c6aed6462300901c00 Mon Sep 17 00:00:00 2001 From: Dieter Lunn Date: Fri, 29 Jan 2021 12:10:20 -0600 Subject: [PATCH 08/12] chore: bump version --- lib/comfy_bootstrap_form/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/comfy_bootstrap_form/version.rb b/lib/comfy_bootstrap_form/version.rb index 2fbefb3..bab9239 100644 --- a/lib/comfy_bootstrap_form/version.rb +++ b/lib/comfy_bootstrap_form/version.rb @@ -2,6 +2,6 @@ module ComfyBootstrapForm - VERSION = "4.0.11" + VERSION = "4.0.12" end From 1a68b52935b29a9d7d789d10ddb9b5ce198d55c4 Mon Sep 17 00:00:00 2001 From: Dieter Lunn Date: Fri, 29 Jan 2021 12:35:30 -0600 Subject: [PATCH 09/12] feat: add support for bootstrap 5 select boxes --- lib/comfy_bootstrap_form/form_builder.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/comfy_bootstrap_form/form_builder.rb b/lib/comfy_bootstrap_form/form_builder.rb index bf0b89f..3108432 100644 --- a/lib/comfy_bootstrap_form/form_builder.rb +++ b/lib/comfy_bootstrap_form/form_builder.rb @@ -92,7 +92,7 @@ def select(method, choices = nil, options = {}, html_options = {}, &block) add_css_class!(html_options, "custom-select") if bootstrap.custom_control - draw_form_group(bootstrap, method, html_options) do + draw_form_group(bootstrap, method, html_options, true) do super(method, choices, options, html_options, &block) end end @@ -107,7 +107,7 @@ def collection_select(method, collection, value_method, text_method, options = { add_css_class!(html_options, "custom-select") if bootstrap.custom_control - draw_form_group(bootstrap, method, html_options) do + draw_form_group(bootstrap, method, html_options, true) do super(method, collection, value_method, text_method, options, html_options) end end @@ -371,11 +371,11 @@ def form_group(options = {}) private # form group wrapper for input fields - def draw_form_group(bootstrap, method, options) + def draw_form_group(bootstrap, method, options, select = false) label = draw_label(bootstrap, method, for_attr: options[:id]) errors = draw_errors(bootstrap, method) - control = draw_control(bootstrap, errors, method, options) do + control = draw_control(bootstrap, errors, method, options, select) do yield end @@ -452,8 +452,9 @@ def draw_label(bootstrap, method, for_attr: nil) end # Renders control for a given field - def draw_control(bootstrap, errors, _method, options) - add_css_class!(options, "form-control") + def draw_control(bootstrap, errors, _method, options, select) + add_css_class!(options, "form-control") unless select + add_css_class!(options, "form-select") if select add_css_class!(options, "is-invalid") if errors.present? draw_control_column(bootstrap, offset: bootstrap.label[:hide]) do From df0701ce87c9bc65fe9fb52e4b94207022a6fd61 Mon Sep 17 00:00:00 2001 From: Dieter Lunn Date: Fri, 29 Jan 2021 12:35:49 -0600 Subject: [PATCH 10/12] chore: bump version --- lib/comfy_bootstrap_form/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/comfy_bootstrap_form/version.rb b/lib/comfy_bootstrap_form/version.rb index bab9239..52dc1dc 100644 --- a/lib/comfy_bootstrap_form/version.rb +++ b/lib/comfy_bootstrap_form/version.rb @@ -2,6 +2,6 @@ module ComfyBootstrapForm - VERSION = "4.0.12" + VERSION = "4.0.13" end From 024d7aa3d17d84d3406d2764f803f8034044a8e8 Mon Sep 17 00:00:00 2001 From: Dieter Lunn Date: Sun, 31 Jan 2021 23:54:55 -0600 Subject: [PATCH 11/12] fix: remove spacing from floating fields --- lib/comfy_bootstrap_form/form_builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/comfy_bootstrap_form/form_builder.rb b/lib/comfy_bootstrap_form/form_builder.rb index 3108432..d566ed5 100644 --- a/lib/comfy_bootstrap_form/form_builder.rb +++ b/lib/comfy_bootstrap_form/form_builder.rb @@ -382,7 +382,7 @@ def draw_form_group(bootstrap, method, options, select = false) form_group_class = "form-group" form_group_class += " row" if bootstrap.horizontal? form_group_class += " mr-sm-2" if bootstrap.inline? - form_group_class += " form-floating mb-2" if bootstrap.floating + form_group_class += " form-floating" if bootstrap.floating content_tag(:div, class: form_group_class) do if bootstrap.floating From 53a41ad82b59ec562b1d1dcd857255f04afa400f Mon Sep 17 00:00:00 2001 From: Dieter Lunn Date: Sun, 31 Jan 2021 23:55:14 -0600 Subject: [PATCH 12/12] chore: bump version --- lib/comfy_bootstrap_form/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/comfy_bootstrap_form/version.rb b/lib/comfy_bootstrap_form/version.rb index 52dc1dc..44e3579 100644 --- a/lib/comfy_bootstrap_form/version.rb +++ b/lib/comfy_bootstrap_form/version.rb @@ -2,6 +2,6 @@ module ComfyBootstrapForm - VERSION = "4.0.13" + VERSION = "4.0.14" end