Class: Superform::Rails::Components::CheckboxComponent

Inherits:
FieldComponent show all
Defined in:
lib/superform/rails.rb

Instance Attribute Summary

Attributes inherited from BaseComponent

#dom, #field

Instance Method Summary collapse

Methods inherited from BaseComponent

#focus, #initialize

Constructor Details

This class inherits a constructor from Superform::Rails::Components::BaseComponent

Instance Method Details

#field_attributesObject



268
269
270
# File 'lib/superform/rails.rb', line 268

def field_attributes
  { id: dom.id, name: dom.name, checked: field.value }
end

#templateObject



260
261
262
263
264
265
266
# File 'lib/superform/rails.rb', line 260

def template(&)
  # Rails has a hidden and checkbox input to deal with sending back a value
  # to the server regardless of if the input is checked or not.
  input(name: dom.name, type: :hidden, value: "0")
  # The hard coded keys need to be in here so the user can't overrite them.
  input(type: :checkbox, value: "1", **attributes)
end