Module: Fae::FormHelper

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

Instance Method Summary collapse

Instance Method Details

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



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

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 if !options[:include_blank].is_a?(String)

  f.association attribute, options
end

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



47
48
49
50
51
# File 'app/helpers/fae/form_helper.rb', line 47

def fae_checkbox(f, attribute, options={})
  options[:type] ||= 'stacked'
  options.update(as: :check_boxes, wrapper_class: "checkbox-wrapper js-checkbox-wrapper #{options[:wrapper_class]} -#{options[:type]}", no_label_div: true)
  association_or_input f, attribute, options
end

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



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

def fae_color_picker(f, attribute, options={})
  options.update(
    as: :string,
    input_class: "js-color-picker color-picker #{'alpha-slider' unless options[:alpha] == false}",
    input_html: { value: f.object.send(attribute).to_s } # value needs to be set to clear color picker
  )
  fae_input f, attribute, options
end

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



72
73
74
75
# File 'app/helpers/fae/form_helper.rb', line 72

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



86
87
88
89
90
91
# File 'app/helpers/fae/form_helper.rb', line 86

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



93
94
95
96
97
98
99
100
101
# File 'app/helpers/fae/form_helper.rb', line 93

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
17
# 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?
  add_input_class(options, 'js-html-editor') if options[:html].present?

  set_maxlength(f, attribute, options)

  f.input attribute, options
end

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



64
65
66
67
68
69
70
# File 'app/helpers/fae/form_helper.rb', line 64

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



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

def fae_prefix(f, attribute, options={})
  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



53
54
55
56
57
58
59
60
61
62
# File 'app/helpers/fae/form_helper.rb', line 53

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



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

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
# File 'app/helpers/fae/form_helper.rb', line 34

def fae_suffix(f, attribute, options={})
  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



103
104
105
106
107
# File 'app/helpers/fae/form_helper.rb', line 103

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] ||= '<div class="youtube-hint"></div>'
  fae_input f, attribute, options
end