Class: Charming::Presentation::Components::Form::Confirm
- Inherits:
-
Field
- Object
- View
- Charming::Presentation::Component
- Field
- Charming::Presentation::Components::Form::Confirm
- Defined in:
- lib/charming/presentation/components/form/confirm.rb
Instance Attribute Summary
Attributes inherited from Field
Instance Method Summary collapse
- #handle_key(event) ⇒ Object
-
#initialize(name, value: false, **options) ⇒ Confirm
constructor
A new instance of Confirm.
- #validate ⇒ Object
Methods inherited from Field
#bind, #focusable?, #render, #value
Methods inherited from View
#focused?, #layout_assigns, #render
Constructor Details
#initialize(name, value: false, **options) ⇒ Confirm
Returns a new instance of Confirm.
8 9 10 11 |
# File 'lib/charming/presentation/components/form/confirm.rb', line 8 def initialize(name, value: false, **) super(name, **) @initial_value = value end |
Instance Method Details
#handle_key(event) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/charming/presentation/components/form/confirm.rb', line 13 def handle_key(event) case Charming.key_of(event) when :space toggle when :y, :right state[:values][name] = true when :n, :left state[:values][name] = false else return nil unless event.respond_to?(:char) && event.char == " " toggle end :handled end |
#validate ⇒ Object
29 30 31 32 33 |
# File 'lib/charming/presentation/components/form/confirm.rb', line 29 def validate return ["must be accepted"] if required? && value != true super end |