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
19 20 21 22 23 24 25 26 |
# File 'app/helpers/fae/form_helper.rb', line 19 def fae_association(f, attribute, ={}) attribute, label_and_hint attribute, list_order f, attribute, set_prompt f, attribute, if ![:include_blank].is_a?(String) f.association attribute, 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, ={}) [:type] ||= 'stacked' .update(as: :check_boxes, wrapper_class: "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
77 78 79 80 81 82 83 84 |
# File 'app/helpers/fae/form_helper.rb', line 77 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
72 73 74 75 |
# File 'app/helpers/fae/form_helper.rb', line 72 def fae_datepicker(f, attribute, ={}) .update(as: :string, wrapper_class: 'datepicker') fae_input f, attribute, 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, ={}) 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
93 94 95 96 97 98 99 100 101 |
# File 'app/helpers/fae/form_helper.rb', line 93 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 |
# 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_maxlength(f, attribute, ) f.input attribute, 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, ={}) 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
28 29 30 31 32 |
# File 'app/helpers/fae/form_helper.rb', line 28 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
53 54 55 56 57 58 59 60 61 62 |
# File 'app/helpers/fae/form_helper.rb', line 53 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
40 41 42 43 44 45 |
# File 'app/helpers/fae/form_helper.rb', line 40 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
34 35 36 37 38 |
# File 'app/helpers/fae/form_helper.rb', line 34 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
103 104 105 106 107 |
# File 'app/helpers/fae/form_helper.rb', line 103 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 |