Sha256: c5e8937b87d2a6625439b7ff1b0ac9f9ee87d238b687ff41448910688c5a3ff3

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

module Formtastic
  module Inputs
    module Base
      module Html
        
        # Defines how the instance of an input should be rendered to a HTML string.
        #
        # @abstract Implement this method in your input class to describe how the input should render itself.
        #
        # @example A basic label and text field input inside a standard wrapping might look like this:
        #     def to_html
        #       input_wrapping do
        #         label_html <<
        #         builder.text_field(method, input_html_options)
        #       end
        #     end
        def to_html
          raise NotImplementedError
        end
        
        def input_html_options
          { 
            :id => dom_id,
            :required => required?,
            :autofocus => autofocus?
          }.merge(options[:input_html] || {})
        end
        
        def dom_id
          [
            builder.custom_namespace, 
            sanitized_object_name, 
            dom_index, 
            association_primary_key || sanitized_method_name
          ].reject { |x| x.blank? }.join('_')
        end
        
        def dom_index
          if builder.options.has_key?(:index)
            builder.options[:index]
          elsif !builder.auto_index.blank?
            # TODO there's no coverage for this case, not sure how to create a scenario for it
            builder.auto_index
          else
            ""
          end
        end

      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
formtastic-2.0.0.rc3 lib/formtastic/inputs/base/html.rb
formtastic-2.0.0.rc2 lib/formtastic/inputs/base/html.rb
formtastic-2.0.0.rc1 lib/formtastic/inputs/base/html.rb