Class: Admin::RadioComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Admin::RadioComponent
- Defined in:
- lib/generators/infold/templates/install/app/components/admin/radio_component.rb
Instance Method Summary collapse
-
#initialize(form, field, list, checked_value: nil, html_class: nil) ⇒ RadioComponent
constructor
A new instance of RadioComponent.
- #radio_button(key) ⇒ Object
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 (key) classes = %W(form-check-input #{@class}) classes << 'is-invalid' if helpers.admin_field_invalid?(@form, @field) @form.(@field, key, class: classes.join(' '), checked: key == (@checked_value || @form.object.send(@field)).to_s) end |