Class: Superform::Rails::Components::Base

Inherits:
Superform::Rails::Component
  • Object
show all
Defined in:
lib/superform/rails/components/base.rb

Direct Known Subclasses

Checkboxes, Field, Label, Radios

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, attributes: nil, **attributes_kwargs) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/superform/rails/components/base.rb', line 9

def initialize(field, attributes: nil, **attributes_kwargs)
  @field = field
  if attributes
    warn "[DEPRECATION] Passing `attributes:` keyword to #{self.class.name} is deprecated. " \
         "Pass HTML attributes as keyword arguments directly instead: " \
         "#{self.class.name}.new(field, **attributes)"
    @attributes = attributes.merge(attributes_kwargs)
  else
    @attributes = attributes_kwargs
  end
end

Instance Attribute Details

#domObject (readonly)

Returns the value of attribute dom.



5
6
7
# File 'lib/superform/rails/components/base.rb', line 5

def dom
  @dom
end

#fieldObject (readonly)

Returns the value of attribute field.



5
6
7
# File 'lib/superform/rails/components/base.rb', line 5

def field
  @field
end

Instance Method Details

#field_attributesObject



21
22
23
# File 'lib/superform/rails/components/base.rb', line 21

def field_attributes
  {}
end

#focus(value = true) ⇒ Object



25
26
27
28
# File 'lib/superform/rails/components/base.rb', line 25

def focus(value = true)
  @attributes[:autofocus] = value
  self
end