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
# 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 button(value = nil, options = {}, &block)
  if value.is_a?(Hash)
    options = value
    value = nil
  end
  value ||= submit_default_value
  render_component(:button, value, options, &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, 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 = {}, &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, options = {}, html_options = {},
                           &block)
  render_component(
    :collection_check_boxes, @object_name, method, collection, value_method, text_method,
    objectify_options(options), @default_html_options.merge(html_options), &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 collection_radio_buttons(
  method, collection,
  value_method, text_method,
  options = {}, html_options = {},
  &block
)
  render_component(
    :collection_radio_buttons, @object_name, method, collection, value_method, text_method,
    objectify_options(options), @default_html_options.merge(html_options), &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, 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



135
136
137
138
139
140
# File 'lib/view_component/form/helpers/rails.rb', line 135

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



44
45
46
47
48
# File 'lib/view_component/form/helpers/rails.rb', line 44

def datetime_field(method, options = {})
  render_component(
    :datetime_local_field, @object_name, method, objectify_options(options)
  )
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, 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



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

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



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,
  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 = {}, &block) ⇒ Object



40
41
42
# File 'lib/view_component/form/helpers/rails.rb', line 40

def label(method, text = nil, options = {}, &block)
  render_component(:label, @object_name, method, text, objectify_options(options), &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 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



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

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 = {}, &block) ⇒ Object



87
88
89
90
91
92
# File 'lib/view_component/form/helpers/rails.rb', line 87

def select(method, choices = nil, options = {}, html_options = {}, &block)
  render_component(
    :select, @object_name, method, choices, objectify_options(options),
    @default_html_options.merge(html_options), &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, options = {})
  if value.is_a?(Hash)
    options = value
    value = nil
  end
  value ||= submit_default_value
  render_component(:submit, value, options)
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, 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



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

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