Module: Fae::FormHelper

Defined in:
app/helpers/fae/form_helper.rb

Instance Method Summary collapse

Instance Method Details

#fae_association(f, attribute, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
# File 'app/helpers/fae/form_helper.rb', line 18

def fae_association(f, attribute, options={})
  custom_options attribute, options
  label_and_hint attribute, options
  list_order f, attribute, options
  set_prompt f, attribute, options

  f.association attribute, options
end

#fae_checkbox(f, attribute, options = {}) ⇒ Object



49
50
51
52
53
54
# File 'app/helpers/fae/form_helper.rb', line 49

def fae_checkbox(f, attribute, options={})
  options[:alignment] = 'checkbox_collection--horizontal' if options[:type] == 'inline'
  options[:alignment] = 'checkbox_collection--vertical' if options[:type] == 'stacked' || options[:type].blank?
  options.update(as: :check_boxes, wrapper_class: "#{options[:wrapper_class]} #{options[:alignment]}", no_label_div: true)
  association_or_input f, attribute, options
end

#fae_datepicker(f, attribute, options = {}) ⇒ Object



75
76
77
78
# File 'app/helpers/fae/form_helper.rb', line 75

def fae_datepicker(f, attribute, options={})
  options.update(as: :string, wrapper_class: 'datepicker')
  fae_input f, attribute, options
end

#fae_daterange(f, attr_array, options = {}) ⇒ Object



80
81
82
83
84
85
# File 'app/helpers/fae/form_helper.rb', line 80

def fae_daterange(f, attr_array, options={})
  raise "Fae::MissingRequiredOption: fae_daterange requires the 'label' option." if options[:label].blank?
  raise "Fae::MalformedArgument: fae_daterange requires an array of two attributes as it's second argument." unless attr_array.present? && attr_array.is_a?(Array) && attr_array.length == 2
  options.update(as: :date_range, start_date: attr_array.first, end_date: attr_array.second)
  fae_input f, options[:label], options
end

#fae_grouped_select(f, attribute, options = {}) ⇒ Object



87
88
89
90
91
92
93
94
95
# File 'app/helpers/fae/form_helper.rb', line 87

def fae_grouped_select(f, attribute, options={})
  raise "Fae::MissingRequiredOption: fae_grouped_select requires a `collection` option or `groups` and `labels` options." if !options.has_key?(:collection) && !options.has_key?(:groups) && !options.has_key?(:labels)
  raise "Fae::MissingRequiredOption: fae_grouped_select required a `labels` option with a value containing an array when using the `groups` option." if options[:groups].present? && options[:labels].blank?
  raise "Fae::MissingRequiredOption: fae_grouped_select required a `groups` option with a value containing an array when using the `labels` option." if options[:labels].present? && options[:groups].blank?

  options[:collection] ||= group_options_for_collection(options[:labels], options[:groups])
  options.update(as: :grouped_select, group_method: :last, wrapper_class: "#{options[:wrapper_class]} select")
  association_or_input f, attribute, options
end

#fae_input(f, attribute, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/fae/form_helper.rb', line 4

def fae_input(f, attribute, options={})
  custom_options attribute, options
  language_support f, attribute, options
  label_and_hint attribute, options
  list_order f, attribute, options
  set_prompt f, attribute, options

  add_input_class(options, 'js-markdown-editor') if options[:markdown].present?

  set_maxlength(f, attribute, options)

  f.input attribute, options
end

#fae_multiselect(f, attribute, options = {}) ⇒ Object



67
68
69
70
71
72
73
# File 'app/helpers/fae/form_helper.rb', line 67

def fae_multiselect(f, attribute, options={})
  raise "Fae::'#{attribute}' must be an association of #{f.object}" if !is_association?(f, attribute)
  raise "Fae::ImproperOptionValue: The value '#{options[:two_pane]}' is not a valid option for 'two_pane'. Please use a Boolean." if options[:two_pane].present? && !!options[:two_pane] != options[:two_pane]

  options.update(input_class: "#{options[:input_class]} multiselect") if options[:two_pane] == true
  fae_association f, attribute, options
end

#fae_prefix(f, attribute, options = {}) ⇒ Object



27
28
29
30
31
32
# File 'app/helpers/fae/form_helper.rb', line 27

def fae_prefix(f, attribute, options={})
  raise "Fae::undefined method '#{attribute}' for #{f.object}" if is_attribute_or_association?(f, attribute) == false
  raise "Fae::MissingRequiredOption: fae_prefix helper method requires the 'prefix' option." if options[:prefix].blank?
  symbol 'prefix', options[:prefix], options
  fae_input f, attribute, options
end

#fae_pulldown(f, attribute, options = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'app/helpers/fae/form_helper.rb', line 56

def fae_pulldown(f, attribute, options={})
  raise "Fae::MissingRequiredOption: fae_pulldown requires a 'collection' when using it on an ActiveRecord attribute." if !options.has_key?(:collection) && f.object.attribute_names.include?(attribute.to_s)
  raise "Fae::ImproperOptionValue: The value #{options[:size]} is not a valid option for 'size'. Please use 'short' or 'long'." if options[:size].present? && ['short','long'].include?(options[:size]) == false
  raise "Fae::ImproperOptionValue: The value #{options[:search]} is not a valid option for 'search'. Please use a Boolean." if options[:search].present? && !!options[:search] != options[:search]

  add_input_class(options, 'small_pulldown') if options[:size] == "short"
  add_input_class(options, 'select-search') if options[:search]
  options.update(wrapper_class: "#{options[:wrapper_class]} select-no_search") if options[:search] == false
  association_or_input f, attribute, options
end

#fae_radio(f, attribute, options = {}) ⇒ Object



42
43
44
45
46
47
# File 'app/helpers/fae/form_helper.rb', line 42

def fae_radio(f, attribute, options={})
  options[:alignment] = 'radio_collection--horizontal' if options[:type] == 'inline'
  options[:alignment] = 'radio_collection--vertical' if options[:type] == 'stacked' || options[:type].blank?
  options.update(as: :radio_collection, wrapper_class: "#{options[:wrapper_class]} #{options[:alignment]}", no_label_div: true)
  association_or_input f, attribute, options
end

#fae_suffix(f, attribute, options = {}) ⇒ Object



34
35
36
37
38
39
# File 'app/helpers/fae/form_helper.rb', line 34

def fae_suffix(f, attribute, options={})
  raise "Fae::undefined method '#{attribute}' for #{f.object}" if is_attribute_or_association?(f, attribute) == false
  raise "Fae::MissingRequiredOption: fae_suffix helper method requires the 'suffix' option." if options[:suffix].blank?
  symbol 'suffix', options[:suffix], options
  fae_input f, attribute, options
end

#fae_video_url(f, attribute, options = {}) ⇒ Object



97
98
99
100
101
102
# File 'app/helpers/fae/form_helper.rb', line 97

def fae_video_url(f, attribute, options={})
  options[:helper_text] ||= "Please enter your YouTube video ID. The video ID is between v= and & of the video's url. This is typically 11 characters long."
  options[:hint] ||= "#{image_tag('fae/youtube_helper.jpg')}"
  options[:input_class] = "#{options[:input_class]} youtube-api"
  fae_input f, attribute, options
end