Class: FoundationRailsHelper::FormBuilder

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

Instance Method Summary collapse

Instance Method Details

#autocomplete(attribute, url, options = {}) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/foundation_rails_helper/form_builder.rb', line 97

def autocomplete(attribute, url, options = {})
  field attribute, options do |opts|
    opts.merge!(:update_elements => opts[:update_elements],
                :min_length => 0, :value => object.send(attribute))
    autocomplete_field(attribute, url, opts)
  end
end

#check_box(attribute, options = {}, checked_value = '1', unchecked_value = '0') ⇒ Object



28
29
30
31
32
33
34
# File 'lib/foundation_rails_helper/form_builder.rb', line 28

def check_box(attribute, options = {}, checked_value = '1', unchecked_value = '0')
  custom_label(attribute, options[:label], options[:label_options]) do
    options.delete(:label)
    options.delete(:label_options)
    super(attribute, options, checked_value, unchecked_value)
  end + error_and_hint(attribute, options)
end

#collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/foundation_rails_helper/form_builder.rb', line 81

def collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {})
  field attribute, options, html_options do |html_opts|
    html_options[:autocomplete] ||= :off
    super(attribute, collection, value_method, text_method, options,
          html_opts)
  end
end

#date_select(attribute, options = {}, html_options = {}) ⇒ Object



61
62
63
64
65
# File 'lib/foundation_rails_helper/form_builder.rb', line 61

def date_select(attribute, options = {}, html_options = {})
  field attribute, options, html_options do |html_opts|
    super(attribute, options, html_opts.merge(:autocomplete => :off))
  end
end

#datetime_select(attribute, options = {}, html_options = {}) ⇒ Object



55
56
57
58
59
# File 'lib/foundation_rails_helper/form_builder.rb', line 55

def datetime_select(attribute, options = {}, html_options = {})
  field attribute, options, html_options do |html_opts|
    super(attribute, options, html_opts.merge(:autocomplete => :off))
  end
end

#grouped_collection_select(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/foundation_rails_helper/form_builder.rb', line 89

def grouped_collection_select(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
  field attribute, options, html_options do |html_opts|
    html_options[:autocomplete] ||= :off
    super(attribute, collection, group_method, group_label_method,
          option_key_method, option_value_method, options, html_opts)
  end
end

#label(attribute, text = nil, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/foundation_rails_helper/form_builder.rb', line 19

def label(attribute, text = nil, options = {})
  if has_error?(attribute)
    options[:class] ||= ''
    options[:class] += ' error'
  end

  super(attribute, (text || '').html_safe, options)
end

#password_field(attribute, options = {}) ⇒ Object



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

def password_field(attribute, options = {})
  field attribute, options do |opts|
    super(attribute, opts.merge(:autocomplete => :off))
  end
end

#radio_button(attribute, tag_value, options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/foundation_rails_helper/form_builder.rb', line 36

def radio_button(attribute, tag_value, options = {})
  options[:label_options] ||= {}
  label_options = options.delete(:label_options).merge!(value: tag_value)
  label_text = options.delete(:label)
  unless label_text == false
    l = label(attribute, label_text, label_options)
  end
  r = @template.radio_button(@object_name, attribute, tag_value,
                             objectify_options(options))

  "#{r}#{l}".html_safe
end

#select(attribute, choices, options = {}, html_options = {}) ⇒ Object



74
75
76
77
78
79
# File 'lib/foundation_rails_helper/form_builder.rb', line 74

def select(attribute, choices, options = {}, html_options = {})
  field attribute, options, html_options do |html_opts|
    html_options[:autocomplete] ||= :off
    super(attribute, choices, options, html_opts)
  end
end

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



105
106
107
108
# File 'lib/foundation_rails_helper/form_builder.rb', line 105

def submit(value = nil, options = {})
  options[:class] ||= FoundationRailsHelper.configuration.button_class
  super(value, options)
end

#time_zone_select(attribute, priorities = nil, options = {}, html_options = {}) ⇒ Object



67
68
69
70
71
72
# File 'lib/foundation_rails_helper/form_builder.rb', line 67

def time_zone_select(attribute, priorities = nil, options = {}, html_options = {})
  field attribute, options, html_options do |html_opts|
    super(attribute, priorities, options,
          html_opts.merge(:autocomplete => :off))
  end
end