Sha256: 29b81a990505f309347b29718659ec5b9ede8446072d80c02c54ca2c1af78029

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

module FormtasticRebootstrap
  module Inputs
    module Base
      module Labelling

        include Formtastic::Inputs::Base::Labelling

        def label_html_options
          super.tap do |options|
            # Bootstrap defines class 'label' too, so remove the
            # one that gets created by Formtastic.
            options[:class] = options[:class].reject { |c| c == 'label' }
            options[:class] << "control-label"
          end
        end

        # def control_label_html
        def label_html
          if render_label?
            template.content_tag(:span, :class => label_class_with_col) do
              builder.label(input_name, label_text, label_html_options)
            end
          else
            "".html_safe
          end
        end

        def layout_classes

        end

        def label_class_with_col
          ['col-md-3 form-label col-form-label'] <<  options.dig(:label_html, :class)&.split(' ')&.select do |c|
            c.match(/^col-(sm|md|lg|xl)?-?[0-9]{1,2}/)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
formtastic_rebootstrap-0.0.2 lib/formtastic_rebootstrap/inputs/base/labelling.rb
formtastic_rebootstrap-0.0.1 lib/formtastic_rebootstrap/inputs/base/labelling.rb