Class: FormFu::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
lib/form_fu/form_builder.rb

Overview

A form builder that produces tableless, lined-up forms.

Instance Method Summary collapse

Instance Method Details

#date_select(field, options = {}, &block) ⇒ Object

wrap the date_select helper



22
23
24
# File 'lib/form_fu/form_builder.rb', line 22

def date_select(field, options={}, &block)
  format_with_label(field, options.merge(:field_type => "date"), super(field, purge_custom_tags(options)), &block)
end

#error_messages(object_name = nil) ⇒ Object

create an error messages helper



69
70
71
# File 'lib/form_fu/form_builder.rb', line 69

def error_messages(object_name = nil)
  @template.error_messages_for object_name || @object_name
end

#image_submit(img_path, options = {}) ⇒ Object

create a image_submit helper



64
65
66
# File 'lib/form_fu/form_builder.rb', line 64

def image_submit(img_path, options = {})
  @template.image_submit_tag(img_path, options)
end

#radio_group(field, choices, options = {}, &block) ⇒ Object

create a radio group helper that works very similarly to the select helper



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/form_fu/form_builder.rb', line 27

def radio_group(field, choices, options={}, &block)  

  # handle special cases
  if choices == :boolean
    choices = [["True", "true"], ["False", "false"]]
  elsif choices == :yes_no
    choices = [["Yes", "yes"], ["No", "no"]]
  elsif choices.class != Array
    choices = []
  end
  
  # build radio choices html 
  choices_html = ""
  choices.each do |key, value|
    radio_html = radio_button_input(field, value)+key
    
    # wrap radio html in a label (for easier selection)
    choices_html << @template.(:label, radio_html, :class => "radio-option")
  end
  
  # wrap the radio-group with a label
  format_with_label(field, options.merge(:field_type => "radio-group"), choices_html, &block)
end

#select(field, choices, options = {}, &block) ⇒ Object



53
54
55
56
# File 'lib/form_fu/form_builder.rb', line 53

def select(field, choices, options={}, &block)
  html_options = options.delete(:html) || {}
  format_with_label(field, options.merge(:field_type => "select"), super(field, choices, options, html_options), &block)
end

#select_inputObject

wrap the select helper



52
# File 'lib/form_fu/form_builder.rb', line 52

alias :select_input :select

#submit(value = "Submit", options = {}) ⇒ Object

create a submit helper



59
60
61
# File 'lib/form_fu/form_builder.rb', line 59

def submit(value = "Submit", options = {})
  @template.submit_tag(value, options)
end

#text_area(field, options = {}, &block) ⇒ Object



17
18
19
# File 'lib/form_fu/form_builder.rb', line 17

def text_area(field, options = {}, &block)
  format_with_label(field, options.merge(:field_type => "text_area"), super(field, purge_custom_tags(options)), &block)
end

#text_area_inputObject



16
# File 'lib/form_fu/form_builder.rb', line 16

alias :text_area_input :text_area