-
+
```
diff --git a/demo/doc/screenshots/bootstrap/index/00_horizontal_form.png b/demo/doc/screenshots/bootstrap/index/00_horizontal_form.png
index a80947b93..532bff724 100644
Binary files a/demo/doc/screenshots/bootstrap/index/00_horizontal_form.png and b/demo/doc/screenshots/bootstrap/index/00_horizontal_form.png differ
diff --git a/demo/doc/screenshots/bootstrap/index/01_with_validation_error.png b/demo/doc/screenshots/bootstrap/index/01_with_validation_error.png
index 6859834de..074b935e2 100644
Binary files a/demo/doc/screenshots/bootstrap/index/01_with_validation_error.png and b/demo/doc/screenshots/bootstrap/index/01_with_validation_error.png differ
diff --git a/demo/doc/screenshots/bootstrap/index/02_inline_form.png b/demo/doc/screenshots/bootstrap/index/02_inline_form.png
index b142e4a08..f07c87564 100644
Binary files a/demo/doc/screenshots/bootstrap/index/02_inline_form.png and b/demo/doc/screenshots/bootstrap/index/02_inline_form.png differ
diff --git a/demo/doc/screenshots/bootstrap/readme/05_example.png b/demo/doc/screenshots/bootstrap/readme/05_example.png
index 4408648d0..b11cab725 100644
Binary files a/demo/doc/screenshots/bootstrap/readme/05_example.png and b/demo/doc/screenshots/bootstrap/readme/05_example.png differ
diff --git a/demo/doc/screenshots/bootstrap/readme/36_example.png b/demo/doc/screenshots/bootstrap/readme/36_example.png
index 79277fa34..2dd87500a 100644
Binary files a/demo/doc/screenshots/bootstrap/readme/36_example.png and b/demo/doc/screenshots/bootstrap/readme/36_example.png differ
diff --git a/demo/doc/screenshots/bootstrap/readme/39_example.png b/demo/doc/screenshots/bootstrap/readme/39_example.png
index 27d20558d..a460a337d 100644
Binary files a/demo/doc/screenshots/bootstrap/readme/39_example.png and b/demo/doc/screenshots/bootstrap/readme/39_example.png differ
diff --git a/demo/doc/screenshots/bootstrap/readme/41_example.png b/demo/doc/screenshots/bootstrap/readme/41_example.png
index 5194c0da2..985394761 100644
Binary files a/demo/doc/screenshots/bootstrap/readme/41_example.png and b/demo/doc/screenshots/bootstrap/readme/41_example.png differ
diff --git a/lib/bootstrap_form/components/labels.rb b/lib/bootstrap_form/components/labels.rb
index 2ba7cc779..8aee89942 100644
--- a/lib/bootstrap_form/components/labels.rb
+++ b/lib/bootstrap_form/components/labels.rb
@@ -23,7 +23,9 @@ def generate_label(id, name, options, custom_label_col, group_layout)
end
def label_classes(name, options, custom_label_col, group_layout)
- classes = ["form-label", options[:class], label_layout_classes(custom_label_col, group_layout)]
+ classes = [options[:class] || label_layout_classes(custom_label_col, group_layout)]
+ add_class = options.delete(:add_class)
+ classes.prepend(add_class) if add_class
classes << "required" if required_field_options(options, name)[:required]
options.delete(:required)
classes << "text-danger" if label_errors && error?(name)
@@ -34,7 +36,9 @@ def label_layout_classes(custom_label_col, group_layout)
if layout_horizontal?(group_layout)
["col-form-label", (custom_label_col || label_col)]
elsif layout_inline?(group_layout)
- ["me-sm-2"]
+ %w[form-label me-sm-2]
+ else
+ "form-label"
end
end
diff --git a/lib/bootstrap_form/form_group.rb b/lib/bootstrap_form/form_group.rb
index e89707881..7cf1525e4 100644
--- a/lib/bootstrap_form/form_group.rb
+++ b/lib/bootstrap_form/form_group.rb
@@ -13,10 +13,8 @@ def form_group(*args, &block)
tag.div(**options.except(:append, :id, :label, :help, :icon,
:input_group_class, :label_col, :control_col,
:add_control_col_class, :layout, :prepend, :floating)) do
- form_group_content(
- generate_label(options[:id], name, options[:label], options[:label_col], options[:layout]),
- generate_help(name, options[:help]), options, &block
- )
+ label = generate_label(options[:id], name, options[:label], options[:label_col], options[:layout])
+ form_group_content(label, generate_help(name, options[:help]), options, &block)
end
end
diff --git a/lib/bootstrap_form/inputs/check_box.rb b/lib/bootstrap_form/inputs/check_box.rb
index 1fa498c99..08a23d762 100644
--- a/lib/bootstrap_form/inputs/check_box.rb
+++ b/lib/bootstrap_form/inputs/check_box.rb
@@ -10,12 +10,13 @@ module CheckBox
def check_box_with_bootstrap(name, options={}, checked_value="1", unchecked_value="0", &block)
options = options.symbolize_keys!
- tag.div(class: check_box_wrapper_class(options), **options[:wrapper].to_h.except(:class)) do
+ content = tag.div(class: check_box_wrapper_class(options), **options[:wrapper].to_h.except(:class)) do
html = check_box_without_bootstrap(name, check_box_options(name, options), checked_value, unchecked_value)
html << check_box_label(name, options, checked_value, &block) unless options[:skip_label]
html << generate_error(name) if options[:error_message]
html
end
+ wrapper(content, options)
end
bootstrap_alias :check_box
@@ -23,6 +24,16 @@ def check_box_with_bootstrap(name, options={}, checked_value="1", unchecked_valu
private
+ def wrapper(content, options)
+ if layout == :inline && !options[:multiple]
+ tag.div(class: "col") { content }
+ elsif layout == :horizontal && !options[:multiple]
+ form_group(layout: layout_in_effect(options[:layout]), label_col: options[:label_col]) { content }
+ else
+ content
+ end
+ end
+
def check_box_options(name, options)
check_box_options = options.except(:class, :label, :label_class, :error_message, :help,
:inline, :hide_label, :skip_label, :wrapper, :wrapper_class, :switch)
@@ -71,7 +82,7 @@ def check_box_label_class(options)
def check_box_wrapper_class(options)
classes = ["form-check"]
classes << "form-check-inline" if layout_inline?(options[:inline])
- classes << "mb-3" unless options[:multiple] || layout == :horizontal
+ classes << "mb-3" unless options[:multiple] || %i[horizontal inline].include?(layout)
classes << "form-switch" if options[:switch]
classes << options.dig(:wrapper, :class).presence
classes << options[:wrapper_class].presence
diff --git a/lib/bootstrap_form/inputs/inputs_collection.rb b/lib/bootstrap_form/inputs/inputs_collection.rb
index e6fc4c637..737a66f9a 100644
--- a/lib/bootstrap_form/inputs/inputs_collection.rb
+++ b/lib/bootstrap_form/inputs/inputs_collection.rb
@@ -6,6 +6,7 @@ module InputsCollection
private
def inputs_collection(name, collection, value, text, options={})
+ options[:label] ||= { class: group_label_class(options[:layout]) }
options[:inline] ||= layout_inline?(options[:layout])
form_group_builder(name, options) do
@@ -21,6 +22,15 @@ def inputs_collection(name, collection, value, text, options={})
end
end
+ def group_label_class(field_layout)
+ if layout_horizontal?(field_layout)
+ group_label_class = "col-form-label #{label_col} pt-0"
+ elsif layout_inline?(field_layout)
+ group_label_class = "form-check form-check-inline ps-0"
+ end
+ group_label_class
+ end
+
# FIXME: Find a way to reduce the parameter list size
# rubocop:disable Metrics/ParameterLists
def form_group_collection_input_options(options, text, obj, index, input_value, collection)
diff --git a/test/bootstrap_checkbox_test.rb b/test/bootstrap_checkbox_test.rb
index e6e279b3a..e9ea7e23f 100644
--- a/test/bootstrap_checkbox_test.rb
+++ b/test/bootstrap_checkbox_test.rb
@@ -125,12 +125,12 @@ class BootstrapCheckboxTest < ActionView::TestCase
expected = <<~HTML