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



20
21
22
# File 'lib/form_fu/form_builder.rb', line 20

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



66
67
68
# File 'lib/form_fu/form_builder.rb', line 66

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



61
62
63
# File 'lib/form_fu/form_builder.rb', line 61

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



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

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(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

wrap the select helper



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

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

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

create a submit helper



56
57
58
# File 'lib/form_fu/form_builder.rb', line 56

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

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



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

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