Class: FoundationFormBuilder::Rails

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
lib/foundation_form_builder/rails.rb

Instance Method Summary collapse

Instance Method Details

#input_div(field_name, label: nil, type: nil, values: nil, field: {}) ⇒ SafeBuffer

Renders a form field with label wrapped in an appropriate <div>, with another <div> for errors if necessary.

Parameters:

  • field_name (String, Symbol)

    Name of the field to render

  • label (String, Symbol) (defaults to: nil)

    Override text for the <label> element

  • type (Symbol) (defaults to: nil)

    Override type of field to render. Known values are :date, :email, :password, :select, :textarea, and :time_zone. Anything else is rendered as a text field.

  • values (Array) (defaults to: nil)

    Name-value pairs for <option> elements. Only meaningful with type: :select.

  • field (Hash) (defaults to: {})

    Options to pass through to the underlying Rails form helper. For type: :time_zone, :priority_zones is also understood.

Returns:

  • (SafeBuffer)

    The rendered HTML

Raises:

  • (ArgumentError)

17
18
19
20
21
22
23
24
25
26
# File 'lib/foundation_form_builder/rails.rb', line 17

def input_div(field_name, label: nil, type: nil, values: nil, field: {})
  raise ArgumentError, ':values is only meaningful with type: :select' if values && type != :select
  @template. :div, class: field_name do
    [
      label(field_name, label),
      input_for(field_name, type, field, values: values),
      error_div(field_name)
    ].compact.join("\n").html_safe
  end
end