Sha256: 74c96b830e8638f2752071e3c09c601133e3b6c9442034737776877613ced524

Contents?: true

Size: 1.48 KB

Versions: 11

Compression:

Stored size: 1.48 KB

Contents

module Formtastic
  module Inputs
    module Base
      # @todo relies on `dom_id`, `required?`, `optional`, `errors?`, `association_primary_key` & `sanitized_method_name` methods from another module
      module Wrapping

        # Override this method if you want to change the display order (for example, rendering the
        # errors before the body of the input).
        def input_wrapping(&block)
          template.content_tag(:li,
            [template.capture(&block), error_html, hint_html].join("\n").html_safe,
            wrapper_html_options
          )
        end

        def wrapper_html_options
          opts = wrapper_html_options_raw
          opts[:class] = wrapper_classes
          opts[:id] = wrapper_dom_id unless opts.has_key? :id
          opts
        end

        def wrapper_html_options_raw
          (options[:wrapper_html] || {}).dup
        end

        def wrapper_classes_raw
          [*wrapper_html_options_raw[:class]]
        end

        def wrapper_classes
          classes = wrapper_classes_raw
          classes << as
          classes << "input"
          classes << "error" if errors?
          classes << "optional" if optional?
          classes << "required" if required?
          classes << "autofocus" if autofocus?

          classes.join(' ')
        end

        def wrapper_dom_id
          @wrapper_dom_id ||= "#{dom_id.to_s.gsub((association_primary_key || method).to_s, sanitized_method_name.to_s)}_input"
        end

      end
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/formtastic-4.0.0/lib/formtastic/inputs/base/wrapping.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/formtastic-4.0.0/lib/formtastic/inputs/base/wrapping.rb
formtastic-4.0.0 lib/formtastic/inputs/base/wrapping.rb
formtastic-4.0.0.rc1 lib/formtastic/inputs/base/wrapping.rb
formtastic-3.1.5 lib/formtastic/inputs/base/wrapping.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/formtastic-3.1.4/lib/formtastic/inputs/base/wrapping.rb
formtastic-3.1.4 lib/formtastic/inputs/base/wrapping.rb
formtastic-3.1.3 lib/formtastic/inputs/base/wrapping.rb
formtastic-3.1.2 lib/formtastic/inputs/base/wrapping.rb
formtastic-3.1.1 lib/formtastic/inputs/base/wrapping.rb
formtastic-3.1.0 lib/formtastic/inputs/base/wrapping.rb