Class: Superform::Rails::Components::Radio

Inherits:
Field
  • Object
show all
Defined in:
lib/superform/rails/components/radio.rb

Instance Attribute Summary

Attributes inherited from Base

#dom, #field

Instance Method Summary collapse

Methods inherited from Base

#focus

Constructor Details

#initialize(field, value:, index: value, **attributes) ⇒ Radio

Returns a new instance of Radio.



5
6
7
8
9
# File 'lib/superform/rails/components/radio.rb', line 5

def initialize(field, value:, index: value, **attributes)
  super(field, **attributes)
  @value = value
  @index = index
end

Instance Method Details

#field_attributesObject



15
16
17
# File 'lib/superform/rails/components/radio.rb', line 15

def field_attributes
  { id: DOM.join(dom.id, @index), name: dom.name, value: @value, checked: field.value == @value }
end

#view_templateObject



11
12
13
# File 'lib/superform/rails/components/radio.rb', line 11

def view_template(&)
  input(type: :radio, **attributes)
end