Class: FoundationRailsHelper::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- FoundationRailsHelper::FormBuilder
- Includes:
- ActionView::Helpers::OutputSafetyHelper, ActionView::Helpers::TagHelper
- Defined in:
- lib/foundation_rails_helper/form_builder.rb
Instance Method Summary collapse
-
#autocomplete(attribute, url, options = {}) ⇒ Object
rubocop:enable LineLength, ParameterLists.
-
#check_box(attribute, options = {}, checked_value = '1', unchecked_value = '0') ⇒ Object
rubocop:disable LineLength.
-
#collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
rubocop:disable LineLength, ParameterLists.
- #date_select(attribute, options = {}, html_options = {}) ⇒ Object
- #datetime_select(attribute, options = {}, html_options = {}) ⇒ Object
- #error_for(attribute, options = {}) ⇒ Object
- #grouped_collection_select(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object
- #label(attribute, text = nil, options = {}) ⇒ Object
- #password_field(attribute, options = {}) ⇒ Object
-
#radio_button(attribute, tag_value, options = {}) ⇒ Object
rubocop:enable LineLength.
-
#select(attribute, choices, options = {}, html_options = {}) ⇒ Object
rubocop:enable LineLength.
- #submit(value = nil, options = {}) ⇒ Object
-
#time_zone_select(attribute, priorities = nil, options = {}, html_options = {}) ⇒ Object
rubocop:disable LineLength.
Instance Method Details
#autocomplete(attribute, url, options = {}) ⇒ Object
rubocop:enable LineLength, ParameterLists
103 104 105 106 107 108 109 |
# File 'lib/foundation_rails_helper/form_builder.rb', line 103 def autocomplete(attribute, url, = {}) field attribute, 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
rubocop:disable LineLength
31 32 33 34 35 36 37 |
# File 'lib/foundation_rails_helper/form_builder.rb', line 31 def check_box(attribute, = {}, checked_value = '1', unchecked_value = '0') custom_label(attribute, [:label], [:label_options]) do .delete(:label) .delete(:label_options) super(attribute, , checked_value, unchecked_value) end + error_and_help_text(attribute, ) end |
#collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
rubocop:disable LineLength, ParameterLists
86 87 88 89 90 91 92 |
# File 'lib/foundation_rails_helper/form_builder.rb', line 86 def collection_select(attribute, collection, value_method, text_method, = {}, = {}) field attribute, , do |html_opts| [:autocomplete] ||= :off super(attribute, collection, value_method, text_method, , html_opts) end end |
#date_select(attribute, options = {}, html_options = {}) ⇒ Object
63 64 65 66 67 |
# File 'lib/foundation_rails_helper/form_builder.rb', line 63 def date_select(attribute, = {}, = {}) field attribute, , do |html_opts| super(attribute, , html_opts.merge(autocomplete: :off)) end end |
#datetime_select(attribute, options = {}, html_options = {}) ⇒ Object
57 58 59 60 61 |
# File 'lib/foundation_rails_helper/form_builder.rb', line 57 def datetime_select(attribute, = {}, = {}) field attribute, , do |html_opts| super(attribute, , html_opts.merge(autocomplete: :off)) end end |
#error_for(attribute, options = {}) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/foundation_rails_helper/form_builder.rb', line 116 def error_for(attribute, = {}) return unless error?(attribute) class_name = 'form-error is-visible' class_name += " #{[:class]}" if [:class] = object.errors[attribute].join(', ') = .html_safe if [:html_safe_errors] content_tag(:small, , class: class_name.sub('is-invalid-input', '')) end |
#grouped_collection_select(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/foundation_rails_helper/form_builder.rb', line 94 def grouped_collection_select(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, = {}, = {}) field attribute, , do |html_opts| [:autocomplete] ||= :off super(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, , html_opts) end end |
#label(attribute, text = nil, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/foundation_rails_helper/form_builder.rb', line 21 def label(attribute, text = nil, = {}) if error?(attribute) [:class] ||= '' [:class] += ' is-invalid-label' end super(attribute, (text || '').html_safe, ) end |
#password_field(attribute, options = {}) ⇒ Object
51 52 53 54 55 |
# File 'lib/foundation_rails_helper/form_builder.rb', line 51 def password_field(attribute, = {}) field attribute, do |opts| super(attribute, opts.merge(autocomplete: :off)) end end |
#radio_button(attribute, tag_value, options = {}) ⇒ Object
rubocop:enable LineLength
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/foundation_rails_helper/form_builder.rb', line 40 def (attribute, tag_value, = {}) [:label_options] ||= {} = .delete(:label_options).merge!(value: tag_value) label_text = .delete(:label) l = label(attribute, label_text, ) unless label_text == false r = @template.(@object_name, attribute, tag_value, ()) "#{r}#{l}".html_safe end |
#select(attribute, choices, options = {}, html_options = {}) ⇒ Object
rubocop:enable LineLength
78 79 80 81 82 83 |
# File 'lib/foundation_rails_helper/form_builder.rb', line 78 def select(attribute, choices, = {}, = {}) field attribute, , do |html_opts| [:autocomplete] ||= :off super(attribute, choices, , html_opts) end end |
#submit(value = nil, options = {}) ⇒ Object
111 112 113 114 |
# File 'lib/foundation_rails_helper/form_builder.rb', line 111 def submit(value = nil, = {}) [:class] ||= FoundationRailsHelper.configuration. super(value, ) end |
#time_zone_select(attribute, priorities = nil, options = {}, html_options = {}) ⇒ Object
rubocop:disable LineLength
70 71 72 73 74 75 |
# File 'lib/foundation_rails_helper/form_builder.rb', line 70 def time_zone_select(attribute, priorities = nil, = {}, = {}) field attribute, , do |html_opts| super(attribute, priorities, , html_opts.merge(autocomplete: :off)) end end |