Class: Admin::CheckboxComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Admin::CheckboxComponent
- Defined in:
- lib/generators/infold/templates/install/app/components/admin/checkbox_component.rb
Instance Method Summary collapse
- #checkbox(key) ⇒ Object
-
#initialize(form, field, list, checked_values: nil, html_class: nil, multiple: true) ⇒ CheckboxComponent
constructor
A new instance of CheckboxComponent.
Constructor Details
#initialize(form, field, list, checked_values: nil, html_class: nil, multiple: true) ⇒ CheckboxComponent
Returns a new instance of CheckboxComponent.
5 6 7 8 9 10 11 12 |
# File 'lib/generators/infold/templates/install/app/components/admin/checkbox_component.rb', line 5 def initialize(form, field, list, checked_values: nil, html_class: nil, multiple: true) @form = form @field = field @list = list @checked_values = checked_values @class = html_class @multiple = multiple end |
Instance Method Details
#checkbox(key) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/generators/infold/templates/install/app/components/admin/checkbox_component.rb', line 14 def checkbox(key) classes = %W(form-check-input #{@class}) classes << 'is-invalid' if helpers.admin_field_invalid?(@form, @field) @form.check_box(@field, { multiple: @multiple, class: classes.join(' '), checked: @checked_values&.include?(key) }, key, nil) end |