Class: Admin::SelectComponent

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

Instance Method Summary collapse

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

#callObject



22
23
24
# File 'lib/generators/infold/templates/install/app/components/admin/select_component.rb', line 22

def call
  select_field
end

#select_fieldObject



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