Class: Superform::Rails::Components::Checkbox

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

Instance Attribute Summary

Attributes inherited from Base

#dom, #field

Instance Method Summary collapse

Methods inherited from Base

#focus, #initialize

Constructor Details

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

Instance Method Details

#field_attributesObject



13
14
15
# File 'lib/superform/rails/components/checkbox.rb', line 13

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

#view_templateObject



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

def view_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