Class: Forms::Checkbox
- Inherits:
-
Phlex::HTML
- Object
- Phlex::HTML
- Forms::Checkbox
- Includes:
- PhlexForms::DelegatedField
- Defined in:
- lib/forms/checkbox.rb
Overview
A model-bound checkbox, delegating to DaisyUI::Checkbox. Emits a hidden field carrying the unchecked value so an unchecked box still submits (the Rails checkbox convention).
Constant Summary
Constants included from PhlexForms::DelegatedField
PhlexForms::DelegatedField::IGNORED_MODIFIERS
Instance Method Summary collapse
-
#initialize(*modifiers, name: nil, id: nil, value: "1", unchecked_value: "0", checked: false, error: false, disabled: false, required: false, **attributes) ⇒ Checkbox
constructor
A new instance of Checkbox.
- #view_template ⇒ Object
Constructor Details
#initialize(*modifiers, name: nil, id: nil, value: "1", unchecked_value: "0", checked: false, error: false, disabled: false, required: false, **attributes) ⇒ Checkbox
Returns a new instance of Checkbox.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/forms/checkbox.rb', line 10 def initialize(*modifiers, name: nil, id: nil, value: "1", unchecked_value: "0", checked: false, error: false, disabled: false, required: false, **attributes) @modifiers = normalize_modifiers(modifiers) @name = name @id = id @value = value @unchecked_value = unchecked_value @checked = checked @error = error @disabled = disabled @required = required @full_width = false @attributes = attributes super() end |
Instance Method Details
#view_template ⇒ Object
26 27 28 29 |
# File 'lib/forms/checkbox.rb', line 26 def view_template input(type: "hidden", name: @name, value: @unchecked_value) if @unchecked_value && @name render DaisyUI::Checkbox.new(*daisy_modifiers, value: @value, **checkbox_attributes) end |