Sha256: a6fafa48adf24d1889a77f41a3077c8849e6fb635e65dd2be57e2722a5b80beb

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module Presenting::FormHelpers
  def present(field)
    send("present_#{field.type}_input", field)
  end
  
  def present_readonly_input(field)
    text_field field.name, :disabled => true, :value => field.value_from(object)
  end
  
  def present_string_input(field)
    text_field field.name, :value => field.value_from(object)
  end
  
  def present_hidden_input(field)
    hidden_field field.name, :value => field.value_from(object)
  end
  
  def present_text_input(field)
    text_area field.name, :value => field.value_from(object)
  end
  
  def present_password_input(field)
    password_field field.name
  end
  
  def present_boolean_input(field)
    check_box field.name
  end
  
  def present_dropdown_input(field)
    view.select_tag "#{object_name}[#{field.name}]", view.options_for_select(field.type_options, object.send(field.name))
  end
  alias_method :present_select_input, :present_dropdown_input
  
  def present_multi_select_input(field)
    view.select_tag "#{object_name}[#{field.name}][]", view.options_for_select(field.type_options, object.send(field.name)), :multiple => true
  end
  
  def present_radios_input(field)
    field.type_options.collect do |(display, value)|
      label("#{field.name}_#{value}", display) +
      radio_button(field.name, value)
    end.join.html_safe
  end
  
  private
  
  def view
    @template
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
presenting-2.0.0 lib/presenting/form_helpers.rb