Class: Components::SelectInputRow

Inherits:
InputRow
  • Object
show all
Defined in:
app/components/select_input_row.rb

Direct Known Subclasses

CollectionSelectInputRow

Instance Method Summary collapse

Constructor Details

#initialize(form:, attribute:, label:, select_options:, help: nil, options: {}) ⇒ SelectInputRow

Returns a new instance of SelectInputRow.



2
3
4
5
# File 'app/components/select_input_row.rb', line 2

def initialize(form:, attribute:, label:, select_options:, help: nil, options: {})
  @select_options = select_options
  super(form: form, attribute: attribute, label: label, help: help, group: options[:button].present?, options: options)
end

Instance Method Details

#input_element ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/components/select_input_row.rb', line 7

def input_element
  raw @form.select( # rubocop:disable Rails/OutputSafety
    @attribute,
    @select_options,
    @options.compact,
    {
      data: {
        controller: "searchable-select"
      },
      class: "form-control form-select #{"is-invalid" if @form.object&.errors&.include?(@attribute_without_id) && !@form.object.errors[@attribute_without_id].empty?}"
    }
  )
  if @options[:button]
    a href: @options[:button][:path], class: "btn btn-secondary" do
      @options[:button][:label]
    end
  end
end