Module: Formtastic::Inputs::Base::Html

Included in:
Formtastic::Inputs::Base
Defined in:
lib/formtastic/inputs/base/html.rb

Instance Method Summary collapse

Instance Method Details

#dom_idObject



28
29
30
31
32
33
34
35
# File 'lib/formtastic/inputs/base/html.rb', line 28

def dom_id
  [
    builder.custom_namespace, 
    sanitized_object_name, 
    dom_index, 
    association_primary_key || sanitized_method_name
  ].reject { |x| x.blank? }.join('_')
end

#dom_indexObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/formtastic/inputs/base/html.rb', line 37

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

#input_html_optionsObject



21
22
23
24
25
26
# File 'lib/formtastic/inputs/base/html.rb', line 21

def input_html_options
  { 
    :id => dom_id,
    :required => required?
  }.merge(options[:input_html] || {})
end

#to_htmlObject

This method is abstract.

Implement this method in your input class to describe how the input should render itself.

Defines how the instance of an input should be rendered to a HTML string.

Examples:

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

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/formtastic/inputs/base/html.rb', line 17

def to_html
  raise NotImplementedError
end