Module: ViewComponent::Form::Helpers::Rails
- Included in:
- Builder
- Defined in:
- lib/view_component/form/helpers/rails.rb
Overview
rubocop:disable Metrics/ModuleLength
Class Method Summary collapse
-
.included(base) ⇒ Object
rubocop:disable Metrics/MethodLength.
Instance Method Summary collapse
- #button(value = nil, options = {}, &block) ⇒ Object
- #check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
- #collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object
- #collection_radio_buttons(method, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object
-
#collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
rubocop:disable Metrics/ParameterLists.
-
#date_select(method, options = {}, html_options = {}) ⇒ Object
rubocop:enable Metrics/ParameterLists.
- #datetime_field(method, options = {}) ⇒ Object (also: #datetime_local_field)
- #datetime_select(method, options = {}, html_options = {}) ⇒ Object
- #file_field(method, options = {}) ⇒ Object
- #grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object
- #label(method, text = nil, options = {}, &block) ⇒ Object
- #radio_button(method, tag_value, options = {}) ⇒ Object
- #rich_text_area(method, options = {}) ⇒ Object
- #select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
- #submit(value = nil, options = {}) ⇒ Object
- #time_select(method, options = {}, html_options = {}) ⇒ Object
- #time_zone_select(method, priority_zones = nil, options = {}, html_options = {}) ⇒ Object
Class Method Details
.included(base) ⇒ Object
rubocop:disable Metrics/MethodLength
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/view_component/form/helpers/rails.rb', line 9 def self.included(base) base.class_eval do (field_helpers - %i[ check_box datetime_field datetime_local_field fields fields_for file_field hidden_field label phone_field radio_button ]).each do |selector| class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def #{selector}(method, options = {}) # def text_field(method, options = {}) render_component( # render_component( :#{selector}, # :text_field, @object_name, # @object_name, method, # method, objectify_options(options), # objectify_options(options), ) # ) end # end RUBY_EVAL end alias_method :phone_field, :telephone_field end end |
Instance Method Details
#button(value = nil, options = {}, &block) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/view_component/form/helpers/rails.rb', line 77 def (value = nil, = {}, &block) if value.is_a?(Hash) = value value = nil end value ||= submit_default_value render_component(:button, value, , &block) end |
#check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
51 52 53 54 55 |
# File 'lib/view_component/form/helpers/rails.rb', line 51 def check_box(method, = {}, checked_value = "1", unchecked_value = "0") render_component( :check_box, @object_name, method, checked_value, unchecked_value, () ) end |
#collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/view_component/form/helpers/rails.rb', line 114 def collection_check_boxes(method, collection, value_method, text_method, = {}, = {}, &block) render_component( :collection_check_boxes, @object_name, method, collection, value_method, text_method, (), @default_html_options.merge(), &block ) end |
#collection_radio_buttons(method, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/view_component/form/helpers/rails.rb', line 122 def ( method, collection, value_method, text_method, = {}, = {}, &block ) render_component( :collection_radio_buttons, @object_name, method, collection, value_method, text_method, (), @default_html_options.merge(), &block ) end |
#collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
rubocop:disable Metrics/ParameterLists
95 96 97 98 99 100 |
# File 'lib/view_component/form/helpers/rails.rb', line 95 def collection_select(method, collection, value_method, text_method, = {}, = {}) render_component( :collection_select, @object_name, method, collection, value_method, text_method, (), @default_html_options.merge() ) end |
#date_select(method, options = {}, html_options = {}) ⇒ Object
rubocop:enable Metrics/ParameterLists
135 136 137 138 139 140 |
# File 'lib/view_component/form/helpers/rails.rb', line 135 def date_select(method, = {}, = {}) render_component( :date_select, @object_name, method, (), @default_html_options.merge() ) end |
#datetime_field(method, options = {}) ⇒ Object Also known as: datetime_local_field
44 45 46 47 48 |
# File 'lib/view_component/form/helpers/rails.rb', line 44 def datetime_field(method, = {}) render_component( :datetime_local_field, @object_name, method, () ) end |
#datetime_select(method, options = {}, html_options = {}) ⇒ Object
142 143 144 145 146 147 |
# File 'lib/view_component/form/helpers/rails.rb', line 142 def datetime_select(method, = {}, = {}) render_component( :datetime_select, @object_name, method, (), @default_html_options.merge() ) end |
#file_field(method, options = {}) ⇒ Object
63 64 65 66 |
# File 'lib/view_component/form/helpers/rails.rb', line 63 def file_field(method, = {}) self.multipart = true render_component(:file_field, @object_name, method, ()) end |
#grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/view_component/form/helpers/rails.rb', line 102 def grouped_collection_select( method, collection, group_method, group_label_method, option_key_method, option_value_method, = {}, = {} ) render_component( :grouped_collection_select, @object_name, method, collection, group_method, group_label_method, option_key_method, option_value_method, (), @default_html_options.merge() ) end |
#label(method, text = nil, options = {}, &block) ⇒ Object
40 41 42 |
# File 'lib/view_component/form/helpers/rails.rb', line 40 def label(method, text = nil, = {}, &block) render_component(:label, @object_name, method, text, (), &block) end |
#radio_button(method, tag_value, options = {}) ⇒ Object
57 58 59 60 61 |
# File 'lib/view_component/form/helpers/rails.rb', line 57 def (method, tag_value, = {}) render_component( :radio_button, @object_name, method, tag_value, () ) end |
#rich_text_area(method, options = {}) ⇒ Object
164 165 166 |
# File 'lib/view_component/form/helpers/rails.rb', line 164 def rich_text_area(method, = {}) render_component(:rich_text_area, @object_name, method, ()) end |
#select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/view_component/form/helpers/rails.rb', line 87 def select(method, choices = nil, = {}, = {}, &block) render_component( :select, @object_name, method, choices, (), @default_html_options.merge(), &block ) end |
#submit(value = nil, options = {}) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/view_component/form/helpers/rails.rb', line 68 def submit(value = nil, = {}) if value.is_a?(Hash) = value value = nil end value ||= submit_default_value render_component(:submit, value, ) end |
#time_select(method, options = {}, html_options = {}) ⇒ Object
149 150 151 152 153 154 |
# File 'lib/view_component/form/helpers/rails.rb', line 149 def time_select(method, = {}, = {}) render_component( :time_select, @object_name, method, (), @default_html_options.merge() ) end |
#time_zone_select(method, priority_zones = nil, options = {}, html_options = {}) ⇒ Object
156 157 158 159 160 161 |
# File 'lib/view_component/form/helpers/rails.rb', line 156 def time_zone_select(method, priority_zones = nil, = {}, = {}) render_component( :time_zone_select, @object_name, method, priority_zones, (), @default_html_options.merge() ) end |