Module: Fae::FormHelper
- Defined in:
- app/helpers/fae/form_helper.rb
Instance Method Summary collapse
- #fae_association(f, attribute, options = {}) ⇒ Object
- #fae_checkbox(f, attribute, options = {}) ⇒ Object
- #fae_color_picker(f, attribute, options = {}) ⇒ Object
- #fae_datepicker(f, attribute, options = {}) ⇒ Object
- #fae_daterange(f, attr_array, options = {}) ⇒ Object
- #fae_grouped_select(f, attribute, options = {}) ⇒ Object
- #fae_input(f, attribute, options = {}) ⇒ Object
- #fae_multiselect(f, attribute, options = {}) ⇒ Object
- #fae_prefix(f, attribute, options = {}) ⇒ Object
- #fae_pulldown(f, attribute, options = {}) ⇒ Object
- #fae_radio(f, attribute, options = {}) ⇒ Object
- #fae_suffix(f, attribute, options = {}) ⇒ Object
- #fae_video_url(f, attribute, options = {}) ⇒ Object
Instance Method Details
#fae_association(f, attribute, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/fae/form_helper.rb', line 21 def fae_association(f, attribute, ={}) attribute, label_and_hint attribute, list_order f, attribute, set_prompt f, attribute, if ![:include_blank].is_a?(String) set_form_manager_container_attr(f, , attribute) unless [:show_form_manager] == false f.association attribute, end |
#fae_checkbox(f, attribute, options = {}) ⇒ Object
51 52 53 54 55 56 |
# File 'app/helpers/fae/form_helper.rb', line 51 def fae_checkbox(f, attribute, ={}) [:type] ||= 'stacked' [:input_type] ||= :check_boxes .update(as: [:input_type], wrapper_class: "input checkbox-wrapper js-checkbox-wrapper #{[:wrapper_class]} -#{[:type]}", no_label_div: true) association_or_input f, attribute, end |
#fae_color_picker(f, attribute, options = {}) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'app/helpers/fae/form_helper.rb', line 82 def fae_color_picker(f, attribute, ={}) .update( as: :string, input_class: "js-color-picker color-picker #{'alpha-slider' unless [:alpha] == false}", input_html: { value: f.object.send(attribute).to_s } # value needs to be set to clear color picker ) fae_input f, attribute, end |
#fae_datepicker(f, attribute, options = {}) ⇒ Object
77 78 79 80 |
# File 'app/helpers/fae/form_helper.rb', line 77 def fae_datepicker(f, attribute, ={}) .update(as: :string, wrapper_class: 'datepicker') fae_input f, attribute, end |
#fae_daterange(f, attr_array, options = {}) ⇒ Object
91 92 93 94 95 96 |
# File 'app/helpers/fae/form_helper.rb', line 91 def fae_daterange(f, attr_array, ={}) raise "Fae::MissingRequiredOption: fae_daterange requires the 'label' option." if [: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 .update(as: :date_range, start_date: attr_array.first, end_date: attr_array.second) fae_input f, [:label], end |
#fae_grouped_select(f, attribute, options = {}) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'app/helpers/fae/form_helper.rb', line 98 def fae_grouped_select(f, attribute, ={}) raise "Fae::MissingRequiredOption: fae_grouped_select requires a `collection` option or `groups` and `labels` options." if !.has_key?(:collection) && !.has_key?(:groups) && !.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 [:groups].present? && [:labels].blank? raise "Fae::MissingRequiredOption: fae_grouped_select required a `groups` option with a value containing an array when using the `labels` option." if [:labels].present? && [:groups].blank? [:collection] ||= ([:labels], [:groups]) .update(as: :grouped_select, group_method: :last, wrapper_class: "#{[:wrapper_class]} select") association_or_input f, attribute, end |
#fae_input(f, attribute, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/helpers/fae/form_helper.rb', line 4 def fae_input(f, attribute, ={}) attribute, language_support f, attribute, label_and_hint attribute, list_order f, attribute, set_prompt f, attribute, add_input_class(, 'js-markdown-editor') if [:markdown].present? add_input_class(, 'js-html-editor') if [:html].present? set_form_manager_container_attr(f, , attribute) unless [:show_form_manager] == false set_maxlength(f, attribute, ) f.input attribute, end |
#fae_multiselect(f, attribute, options = {}) ⇒ Object
69 70 71 72 73 74 75 |
# File 'app/helpers/fae/form_helper.rb', line 69 def fae_multiselect(f, attribute, ={}) raise "Fae::'#{attribute}' must be an association of #{f.object}" if !is_association?(f, attribute) raise "Fae::ImproperOptionValue: The value '#{[:two_pane]}' is not a valid option for 'two_pane'. Please use a Boolean." if [:two_pane].present? && !![:two_pane] != [:two_pane] .update(input_class: "#{[:input_class]} multiselect") if [:two_pane] == true fae_association f, attribute, end |
#fae_prefix(f, attribute, options = {}) ⇒ Object
32 33 34 35 36 |
# File 'app/helpers/fae/form_helper.rb', line 32 def fae_prefix(f, attribute, ={}) raise "Fae::MissingRequiredOption: fae_prefix helper method requires the 'prefix' option." if [:prefix].blank? symbol 'prefix', [:prefix], fae_input f, attribute, end |
#fae_pulldown(f, attribute, options = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'app/helpers/fae/form_helper.rb', line 58 def fae_pulldown(f, attribute, ={}) raise "Fae::MissingRequiredOption: fae_pulldown requires a 'collection' when using it on an ActiveRecord attribute." if !.has_key?(:collection) && f.object.attribute_names.include?(attribute.to_s) raise "Fae::ImproperOptionValue: The value #{[:size]} is not a valid option for 'size'. Please use 'short' or 'long'." if [:size].present? && ['short','long'].include?([:size]) == false raise "Fae::ImproperOptionValue: The value #{[:search]} is not a valid option for 'search'. Please use a Boolean." if [:search].present? && !![:search] != [:search] add_input_class(, 'small_pulldown') if [:size] == "short" add_input_class(, 'select-search') if [:search] .update(wrapper_class: "#{[:wrapper_class]} select-no_search") if [:search] == false association_or_input f, attribute, end |
#fae_radio(f, attribute, options = {}) ⇒ Object
44 45 46 47 48 49 |
# File 'app/helpers/fae/form_helper.rb', line 44 def fae_radio(f, attribute, ={}) [:alignment] = 'radio_collection--horizontal' if [:type] == 'inline' [:alignment] = 'radio_collection--vertical' if [:type] == 'stacked' || [:type].blank? .update(as: :radio_collection, wrapper_class: "#{[:wrapper_class]} #{[:alignment]}", no_label_div: true) association_or_input f, attribute, end |
#fae_suffix(f, attribute, options = {}) ⇒ Object
38 39 40 41 42 |
# File 'app/helpers/fae/form_helper.rb', line 38 def fae_suffix(f, attribute, ={}) raise "Fae::MissingRequiredOption: fae_suffix helper method requires the 'suffix' option." if [:suffix].blank? symbol 'suffix', [:suffix], fae_input f, attribute, end |
#fae_video_url(f, attribute, options = {}) ⇒ Object
108 109 110 111 112 |
# File 'app/helpers/fae/form_helper.rb', line 108 def fae_video_url(f, attribute, ={}) [: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." [:hint] ||= '<div class="youtube-hint"></div>' fae_input f, attribute, end |