Class: Railsboot::FormField::SelectComponent

Inherits:
FieldComponent
  • Object
show all
Defined in:
app/components/railsboot/form_field/select_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(form:, name:, size: DEFAULT_SIZE, choices: nil, options: {}, **html_attributes) ⇒ SelectComponent

Returns a new instance of SelectComponent.



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/components/railsboot/form_field/select_component.rb', line 2

def initialize(form:, name:, size: DEFAULT_SIZE, choices: nil, options: {}, **html_attributes)
  @form = form
  @name = name
  @size = fetch_or_fallback(size, SIZES, DEFAULT_SIZE)
  @choices = choices
  @options = options
  @html_attributes = html_attributes

  @html_attributes[:class] = class_names(
    "form-select",
    {"form-select-#{@size}" => @size.present?},
    html_attributes[:class]
  )
end

Instance Method Details

#callObject



17
18
19
# File 'app/components/railsboot/form_field/select_component.rb', line 17

def call
  @form.select @name, @choices, @options, **@html_attributes
end