Module: StimulusPlumbers::Form::Fields::Inputs::Choice

Included in:
Builder
Defined in:
lib/stimulus_plumbers/form/fields/inputs/choice.rb

Instance Method Summary collapse

Instance Method Details

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



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/stimulus_plumbers/form/fields/inputs/choice.rb', line 8

def check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0")
  options[:layout] ||= :inline
  Field.new(@template, **options).render(
    object,
    attribute,
    input_id: field_id(attribute)
  ) do |html_opts, opts, error|
    html_options = merge_html_options(opts, html_opts, field_theme(:form_checkbox, error: error))
    super(attribute, html_options, checked_value, unchecked_value)
  end
end

#collection_check_boxes(attribute, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/stimulus_plumbers/form/fields/inputs/choice.rb', line 20

def collection_check_boxes(
  attribute,
  collection,
  value_method,
  text_method,
  options = {},
  html_options = {},
  &block
)
  options[:layout] ||= :inline
  field = Field.new(@template, **options)
  render_fieldset(attribute, field) do |error|
    item_opts = merge_html_options(html_options, field_theme(:form_checkbox, error: error))
    super(attribute, collection, value_method, text_method, {}, item_opts, &block)
  end
end

#collection_radio_buttons(attribute, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/stimulus_plumbers/form/fields/inputs/choice.rb', line 49

def collection_radio_buttons(
  attribute,
  collection,
  value_method,
  text_method,
  options = {},
  html_options = {},
  &block
)
  options[:layout] ||= :inline
  field = Field.new(@template, **options)
  render_fieldset(attribute, field) do |error|
    item_opts = merge_html_options(html_options, field_theme(:form_radio, error: error))
    super(attribute, collection, value_method, text_method, {}, item_opts, &block)
  end
end

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



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/stimulus_plumbers/form/fields/inputs/choice.rb', line 37

def radio_button(attribute, tag_value, options = {})
  options[:layout] ||= :inline
  Field.new(@template, **options).render(
    object,
    attribute,
    input_id: field_id(attribute, tag_value)
  ) do |html_opts, opts, error|
    html_options = merge_html_options(opts, html_opts, field_theme(:form_radio, error: error))
    super(attribute, tag_value, html_options)
  end
end