Class: Alchemy::Admin::ElementSelect

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/alchemy/admin/element_select.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elements, field_name: "element[name]") ⇒ ElementSelect

Returns a new instance of ElementSelect.



8
9
10
11
# File 'app/components/alchemy/admin/element_select.rb', line 8

def initialize(elements, field_name: "element[name]")
  @field_name = field_name
  @elements = elements
end

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



6
7
8
# File 'app/components/alchemy/admin/element_select.rb', line 6

def elements
  @elements
end

#field_nameObject (readonly)

Returns the value of attribute field_name.



6
7
8
# File 'app/components/alchemy/admin/element_select.rb', line 6

def field_name
  @field_name
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
# File 'app/components/alchemy/admin/element_select.rb', line 13

def call
  text_field_tag(field_name, nil, {
    "data-options": elements_options.to_json,
    "data-placeholder": Alchemy.t(:select_element),
    is: "alchemy-element-select",
    autofocus: true,
    required: true,
    value: elements.many? ? nil : elements.first&.name
  })
end