Class: Panda::Core::Admin::FormSelectComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/panda/core/admin/form_select_component.rb

Constant Summary

Constants inherited from Base

Base::TAILWIND_MERGER

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prompt:, name: "", options: [], required: false, disabled: false, include_blank: false, **attrs) ⇒ FormSelectComponent

Returns a new instance of FormSelectComponent.



7
8
9
10
11
12
13
14
15
# File 'app/components/panda/core/admin/form_select_component.rb', line 7

def initialize(prompt:, name: "", options: [], required: false, disabled: false, include_blank: false, **attrs)
  @name = name
  @options = options
  @prompt = prompt
  @required = required
  @disabled = disabled
  @include_blank = include_blank
  super(**attrs)
end

Instance Attribute Details

#disabledObject (readonly)

Returns the value of attribute disabled.



17
18
19
# File 'app/components/panda/core/admin/form_select_component.rb', line 17

def disabled
  @disabled
end

#include_blankObject (readonly)

Returns the value of attribute include_blank.



17
18
19
# File 'app/components/panda/core/admin/form_select_component.rb', line 17

def include_blank
  @include_blank
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'app/components/panda/core/admin/form_select_component.rb', line 17

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'app/components/panda/core/admin/form_select_component.rb', line 17

def options
  @options
end

#promptObject (readonly)

Returns the value of attribute prompt.



17
18
19
# File 'app/components/panda/core/admin/form_select_component.rb', line 17

def prompt
  @prompt
end

#requiredObject (readonly)

Returns the value of attribute required.



17
18
19
# File 'app/components/panda/core/admin/form_select_component.rb', line 17

def required
  @required
end

Instance Method Details

#default_attrsObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/components/panda/core/admin/form_select_component.rb', line 19

def default_attrs
  base_attrs = {
    name: @name,
    id: @name.to_s.gsub(/[\[\]]/, "_").gsub("__", "_").chomp("_"),
    class: select_classes
  }

  base_attrs[:required] = true if @required
  base_attrs[:disabled] = true if @disabled

  base_attrs
end