diff --git a/demo/app/views/users/_horizontal_form.html.erb b/demo/app/views/users/_horizontal_form.html.erb index 827f217..c9eb035 100644 --- a/demo/app/views/users/_horizontal_form.html.erb +++ b/demo/app/views/users/_horizontal_form.html.erb @@ -13,7 +13,7 @@ <%= form.radio_button :terms, bootstrap_form: {switch: false}, required: true %> <%= form.range_field :excellence %> <%= form.url_field :blog_url %> - <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {bootstrap_form: {inline: true}, checked: form.object.fruit_id} %> + <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {bootstrap_form: {inline: false}, checked: form.object.fruit_id} %> <%= form.color_field :favorite_color %> <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {bootstrap_form: {inline: true}} %> <%= form.fields_for :address, include_id: false, bootstrap_form: {layout: :horizontal} do |address_form| %> diff --git a/lib/rails_bootstrap_form/components/check_box.rb b/lib/rails_bootstrap_form/components/check_box.rb index 44ad5b1..d30888a 100644 --- a/lib/rails_bootstrap_form/components/check_box.rb +++ b/lib/rails_bootstrap_form/components/check_box.rb @@ -62,11 +62,18 @@ def check_box_wrapper_class(bootstrap_options) classes = Array("form-check") classes << "form-switch" if bootstrap_options.switch classes << "form-check-inline" if bootstrap_options.inline? - classes << "mb-3" if bootstrap_options.layout_vertical? + classes << "mb-3" if (!bootstrap_options.inline? && !bootstrap_options.layout_horizontal?) classes.flatten.compact end - private :check_box_label, :check_box_classes, :check_box_label_class, :check_box_wrapper_class + def check_box_container_classes(bootstrap_options) + classes = [bootstrap_options.field_col_wrapper_class] + classes << bootstrap_options.field_offset_class unless bootstrap_options.inline? + classes.flatten.compact + end + + private :check_box_label, :check_box_classes, :check_box_label_class, + :check_box_wrapper_class, :check_box_container_classes end end end diff --git a/lib/rails_bootstrap_form/components/radio_button.rb b/lib/rails_bootstrap_form/components/radio_button.rb index c62622e..4a8cf13 100644 --- a/lib/rails_bootstrap_form/components/radio_button.rb +++ b/lib/rails_bootstrap_form/components/radio_button.rb @@ -58,11 +58,18 @@ def radio_button_label_class(attribute, bootstrap_options, options) def radio_button_wrapper_class(bootstrap_options) classes = Array("form-check") classes << "form-check-inline" if bootstrap_options.inline? - classes << "mb-3" if bootstrap_options.layout_vertical? + classes << "mb-3" if (!bootstrap_options.inline? && !bootstrap_options.layout_horizontal?) classes.flatten.compact end - private :radio_button_label, :radio_button_classes, :radio_button_label_class, :radio_button_wrapper_class + def radio_button_container_classes(bootstrap_options) + classes = [bootstrap_options.field_col_wrapper_class] + classes << bootstrap_options.field_offset_class unless bootstrap_options.inline? + classes.flatten.compact + end + + private :radio_button_label, :radio_button_classes, :radio_button_label_class, + :radio_button_wrapper_class, :radio_button_container_classes end end end diff --git a/lib/rails_bootstrap_form/inputs.rb b/lib/rails_bootstrap_form/inputs.rb index 5831d07..4398d11 100644 --- a/lib/rails_bootstrap_form/inputs.rb +++ b/lib/rails_bootstrap_form/inputs.rb @@ -140,18 +140,15 @@ def check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0 check_box_html = tag.div(**check_box_wrapper_options(bootstrap_options)) do concat(check_box_field) concat(check_box_label) - concat(check_box_help_text) unless bootstrap_options.inline? concat(generate_error(attribute)) if (is_invalid?(attribute) && !bootstrap_options.inline?) + concat(check_box_help_text) unless bootstrap_options.inline? end if (bootstrap_options.inline? || bootstrap_options.layout_vertical?) check_box_html else - check_box_container_classes = [bootstrap_options.field_col_wrapper_class] - check_box_container_classes << bootstrap_options.field_offset_class unless bootstrap_options.inline? - tag.div(class: field_wrapper_classes(bootstrap_options)) do - tag.div(class: check_box_container_classes) do + tag.div(class: check_box_container_classes(bootstrap_options)) do check_box_html end end @@ -171,18 +168,15 @@ def radio_button(attribute, value, options = {}) radio_button_html = tag.div(**radio_button_wrapper_options(bootstrap_options)) do concat(radio_button_field) concat(radio_button_label) - concat(radio_button_help_text) unless bootstrap_options.inline? concat(generate_error(attribute)) if (is_invalid?(attribute) && !bootstrap_options.inline?) + concat(radio_button_help_text) unless bootstrap_options.inline? end if (bootstrap_options.inline? || bootstrap_options.layout_vertical?) radio_button_html else - radio_button_container_classes = [bootstrap_options.field_col_wrapper_class] - radio_button_container_classes << bootstrap_options.field_offset_class unless bootstrap_options.inline? - tag.div(class: field_wrapper_classes(bootstrap_options)) do - tag.div(class: radio_button_container_classes) do + tag.div(class: radio_button_container_classes(bootstrap_options)) do radio_button_html end end