Last active
October 4, 2023 08:56
-
-
Save istvanp/9d7dedff7c56f69d5524c054565ae42a to your computer and use it in GitHub Desktop.
Bootstrap v5 bootstrap_form Floating Labels support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/bootstrap_form.rb | |
module BootstrapForm | |
module FormGroup | |
def form_group_classes(options) | |
classes = ['mb-3', options[:class].try(:split)].flatten.compact | |
classes << 'form-label-group' if options[:layout] == :floating | |
classes << 'row' if horizontal_group_with_gutters?(options[:layout], classes) | |
classes << 'col-auto g-3' if field_inline_override?(options[:layout]) | |
classes << feedback_class if options[:icon] | |
classes | |
end | |
def form_group_content(label, help_text, options, &block) | |
if group_layout_horizontal?(options[:layout]) | |
concat(label).concat(tag.div(capture(&block) + help_text, class: form_group_control_class(options))) | |
elsif options[:layout] == :floating | |
concat(capture(&block)) | |
concat(label) | |
concat(help_text) if help_text | |
else | |
concat(label) | |
concat(capture(&block)) | |
concat(help_text) if help_text | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps:
:floating
: