Class: Admin::SelectComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Admin::SelectComponent
- Defined in:
- lib/generators/infold/templates/install/app/components/admin/select_component.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(form, field, list, blank: true, selected_value: nil) ⇒ SelectComponent
constructor
A new instance of SelectComponent.
- #select_field ⇒ Object
Constructor Details
#initialize(form, field, list, blank: true, selected_value: nil) ⇒ SelectComponent
Returns a new instance of SelectComponent.
5 6 7 8 9 10 11 |
# File 'lib/generators/infold/templates/install/app/components/admin/select_component.rb', line 5 def initialize(form, field, list, blank:true, selected_value:nil) @form = form @field = field @list = list @blank = blank @selected_value = selected_value end |
Instance Method Details
#call ⇒ Object
22 23 24 |
# File 'lib/generators/infold/templates/install/app/components/admin/select_component.rb', line 22 def call select_field end |
#select_field ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/generators/infold/templates/install/app/components/admin/select_component.rb', line 13 def select_field classes = %W(form-select #{@class}) classes << 'is-invalid' if helpers.admin_field_invalid?(@form, @field) @form.select(@field, @list, { include_blank: @blank, selected: @selected_value || @form.object.send(@field).to_s }, { class: classes.join(' ') }) end |