Class: Panda::Core::Admin::FormInputComponent

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

Constant Summary

Constants inherited from Base

Base::TAILWIND_MERGER

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: "", value: nil, placeholder: nil, autocomplete: nil, type: :text, required: false, disabled: false, **attrs) ⇒ FormInputComponent

Returns a new instance of FormInputComponent.



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

def initialize(name: "", value: nil, placeholder: nil, autocomplete: nil, type: :text, required: false, disabled: false, **attrs)
  @name = name
  @value = value
  @type = type
  @placeholder = placeholder
  @required = required
  @disabled = disabled
  @autocomplete = autocomplete
  super(**attrs)
end

Instance Attribute Details

#autocompleteObject (readonly)

Returns the value of attribute autocomplete.



18
19
20
# File 'app/components/panda/core/admin/form_input_component.rb', line 18

def autocomplete
  @autocomplete
end

#disabledObject (readonly)

Returns the value of attribute disabled.



18
19
20
# File 'app/components/panda/core/admin/form_input_component.rb', line 18

def disabled
  @disabled
end

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'app/components/panda/core/admin/form_input_component.rb', line 18

def name
  @name
end

#placeholderObject (readonly)

Returns the value of attribute placeholder.



18
19
20
# File 'app/components/panda/core/admin/form_input_component.rb', line 18

def placeholder
  @placeholder
end

#requiredObject (readonly)

Returns the value of attribute required.



18
19
20
# File 'app/components/panda/core/admin/form_input_component.rb', line 18

def required
  @required
end

#typeObject (readonly)

Returns the value of attribute type.



18
19
20
# File 'app/components/panda/core/admin/form_input_component.rb', line 18

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



18
19
20
# File 'app/components/panda/core/admin/form_input_component.rb', line 18

def value
  @value
end

Instance Method Details

#default_attrsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/components/panda/core/admin/form_input_component.rb', line 20

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

  base_attrs[:value] = @value if @value
  base_attrs[:placeholder] = @placeholder if @placeholder
  base_attrs[:required] = true if @required
  base_attrs[:disabled] = true if @disabled
  base_attrs[:autocomplete] = @autocomplete if @autocomplete

  base_attrs
end