Class: Admin::RadioComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
lib/generators/infold/templates/install/app/components/admin/radio_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(form, field, list, checked_value: nil, html_class: nil) ⇒ RadioComponent

Returns a new instance of RadioComponent.



5
6
7
8
9
10
11
# File 'lib/generators/infold/templates/install/app/components/admin/radio_component.rb', line 5

def initialize(form, field, list, checked_value: nil, html_class: nil)
  @form = form
  @field = field
  @list = list
  @checked_value = checked_value
  @class = html_class
end

Instance Method Details

#radio_button(key) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/generators/infold/templates/install/app/components/admin/radio_component.rb', line 13

def radio_button(key)
  classes = %W(form-check-input #{@class})
  classes << 'is-invalid' if helpers.admin_field_invalid?(@form, @field)
  @form.radio_button(@field,
                     key,
                     class: classes.join(' '),
                     checked: key == (@checked_value || @form.object.send(@field)).to_s)
end