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

Instance Method Summary collapse

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
37
38
39
40
# File 'lib/view_component/form/helpers/rails.rb', line 9

def self.included(base)
  base.class_eval do # rubocop:disable Metrics/BlockLength
    (field_helpers - i[
      text_area
      textarea
      check_box
      checkbox
      datetime_field
      datetime_local_field
      fields
      fields_for
      file_field
      hidden_field
      label
      phone_field
      radio_button
    ]).each do |selector|
      class_eval "        def \#{selector}(method, options = {}) # def text_field(method, options = {})\n          render_component(                   #   render_component(\n            :\#{selector},                     #     :text_field,\n            @object_name,                     #     @object_name,\n            method,                           #     method,\n            objectify_options(options),       #     objectify_options(options),\n          )                                   #   )\n        end                                   # end\n      RUBY_EVAL\n    end\n\n    alias_method :phone_field, :telephone_field\n  end\nend\n", __FILE__, __LINE__ + 1

Instance Method Details

#button(value = nil, options = {}) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/view_component/form/helpers/rails.rb', line 83

def button(value = nil, options = {}, &)
  if value.is_a?(Hash)
    options = value
    value = nil
  end
  value ||= submit_default_value
  render_component(:button, value, options, &)
end

#check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object



59
60
61
# File 'lib/view_component/form/helpers/rails.rb', line 59

def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
  render_component(:check_box, @object_name, method, checked_value, unchecked_value, objectify_options(options))
end

#collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object



120
121
122
123
124
125
126
# File 'lib/view_component/form/helpers/rails.rb', line 120

def collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {},
                           &)
  render_component(
    :collection_check_boxes, @object_name, method, collection, value_method, text_method,
    objectify_options(options), @default_html_options.merge(html_options), &
  )
end

#collection_radio_buttons(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
# File 'lib/view_component/form/helpers/rails.rb', line 128

def collection_radio_buttons(
  method, collection,
  value_method, text_method,
  options = {}, html_options = {},
  &
)
  render_component(
    :collection_radio_buttons, @object_name, method, collection, value_method, text_method,
    objectify_options(options), @default_html_options.merge(html_options), &
  )
end

#collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object

rubocop:disable Metrics/ParameterLists



101
102
103
104
105
106
# File 'lib/view_component/form/helpers/rails.rb', line 101

def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
  render_component(
    :collection_select, @object_name, method, collection, value_method, text_method,
    objectify_options(options), @default_html_options.merge(html_options)
  )
end

#date_select(method, options = {}, html_options = {}) ⇒ Object

rubocop:enable Metrics/ParameterLists



141
142
143
144
145
146
# File 'lib/view_component/form/helpers/rails.rb', line 141

def date_select(method, options = {}, html_options = {})
  render_component(
    :date_select, @object_name, method,
    objectify_options(options), @default_html_options.merge(html_options)
  )
end

#datetime_field(method, options = {}) ⇒ Object Also known as: datetime_local_field



52
53
54
55
56
# File 'lib/view_component/form/helpers/rails.rb', line 52

def datetime_field(method, options = {})
  render_component(
    :datetime_local_field, @object_name, method, objectify_options(options)
  )
end

#datetime_select(method, options = {}, html_options = {}) ⇒ Object



148
149
150
151
152
153
# File 'lib/view_component/form/helpers/rails.rb', line 148

def datetime_select(method, options = {}, html_options = {})
  render_component(
    :datetime_select, @object_name, method,
    objectify_options(options), @default_html_options.merge(html_options)
  )
end

#file_field(method, options = {}) ⇒ Object



69
70
71
72
# File 'lib/view_component/form/helpers/rails.rb', line 69

def file_field(method, options = {})
  self.multipart = true
  render_component(:file_field, @object_name, method, objectify_options(options))
end

#grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/view_component/form/helpers/rails.rb', line 108

def grouped_collection_select(
  method, collection,
  group_method, group_label_method, option_key_method, option_value_method,
  options = {}, html_options = {}
)
  render_component(
    :grouped_collection_select, @object_name, method, collection, group_method,
    group_label_method, option_key_method, option_value_method,
    objectify_options(options), @default_html_options.merge(html_options)
  )
end

#label(method, text = nil, options = {}) ⇒ Object



48
49
50
# File 'lib/view_component/form/helpers/rails.rb', line 48

def label(method, text = nil, options = {}, &)
  render_component(:label, @object_name, method, text, objectify_options(options), &)
end

#radio_button(method, tag_value, options = {}) ⇒ Object



63
64
65
66
67
# File 'lib/view_component/form/helpers/rails.rb', line 63

def radio_button(method, tag_value, options = {})
  render_component(
    :radio_button, @object_name, method, tag_value, objectify_options(options)
  )
end

#rich_text_area(method, options = {}) ⇒ Object



170
171
172
# File 'lib/view_component/form/helpers/rails.rb', line 170

def rich_text_area(method, options = {})
  render_component(:rich_text_area, @object_name, method, objectify_options(options))
end

#select(method, choices = nil, options = {}, html_options = {}) ⇒ Object



93
94
95
96
97
98
# File 'lib/view_component/form/helpers/rails.rb', line 93

def select(method, choices = nil, options = {}, html_options = {}, &)
  render_component(
    :select, @object_name, method, choices, objectify_options(options),
    @default_html_options.merge(html_options), &
  )
end

#submit(value = nil, options = {}) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/view_component/form/helpers/rails.rb', line 74

def submit(value = nil, options = {})
  if value.is_a?(Hash)
    options = value
    value = nil
  end
  value ||= submit_default_value
  render_component(:submit, value, options)
end

#text_area(method, options = {}) ⇒ Object

rubocop:enable Metrics/MethodLength



43
44
45
# File 'lib/view_component/form/helpers/rails.rb', line 43

def text_area(method, options = {})
  render_component(:text_area, @object_name, method, objectify_options(options))
end

#time_select(method, options = {}, html_options = {}) ⇒ Object



155
156
157
158
159
160
# File 'lib/view_component/form/helpers/rails.rb', line 155

def time_select(method, options = {}, html_options = {})
  render_component(
    :time_select, @object_name, method,
    objectify_options(options), @default_html_options.merge(html_options)
  )
end

#time_zone_select(method, priority_zones = nil, options = {}, html_options = {}) ⇒ Object



162
163
164
165
166
167
# File 'lib/view_component/form/helpers/rails.rb', line 162

def time_zone_select(method, priority_zones = nil, options = {}, html_options = {})
  render_component(
    :time_zone_select, @object_name, method, priority_zones,
    objectify_options(options), @default_html_options.merge(html_options)
  )
end