Class: Forme::Labeler::Bootstrap5

Inherits:
Explicit
  • Object
show all
Defined in:
lib/forme/bs5.rb

Instance Method Summary collapse

Instance Method Details

#call(tag, input) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/forme/bs5.rb', line 119

def call(tag, input)
  floating_label = (input.opts[:wrapper_attr] || {})[:class].to_s.include?("form-floating")
  input.opts[:label_position] ||= :after if floating_label

  tags = super
  return tags if floating_label

  attr = tags.find { |tag| tag.is_a?(Tag) && tag.type == :label }.attr

  label_class = case input.type
  when :radio, :checkbox
    "form-check-label"
  else
    "form-label"
  end
  Forme.attr_classes_after(attr, label_class)

  tags
end