Class: Charming::Presentation::Components::Form::Note

Inherits:
Field show all
Defined in:
lib/charming/presentation/components/form/note.rb

Overview

Note is a non-interactive Form field that renders a static string of text. Notes never receive focus, never validate, and store no value — they are presentational only, useful for headings, dividers, or instructional text inside a form.

Instance Attribute Summary

Attributes inherited from Field

#help, #label, #name, #state

Instance Method Summary collapse

Methods inherited from Field

#handle_key, #value

Methods inherited from View

#focused?, #layout_assigns

Constructor Details

#initialize(text, name: :note, theme: nil) ⇒ Note

text is the literal string to render. name is unused (defaults to :note) and exists only because the Field base class requires a name.



13
14
15
16
# File 'lib/charming/presentation/components/form/note.rb', line 13

def initialize(text, name: :note, theme: nil)
  super(name, theme: theme)
  @text = text
end

Instance Method Details

#bind(state) ⇒ Object

Binds the field to the form state but does not create any per-field storage.



19
20
21
# File 'lib/charming/presentation/components/form/note.rb', line 19

def bind(state)
  @state = state
end

#focusable?Boolean

Notes are never focusable and therefore excluded from Tab/Enter traversal.

Returns:

  • (Boolean)


24
25
26
# File 'lib/charming/presentation/components/form/note.rb', line 24

def focusable?
  false
end

#render(active: false) ⇒ Object

Returns the literal text, ignoring the active: flag (notes have no focus state).



34
35
36
# File 'lib/charming/presentation/components/form/note.rb', line 34

def render(active: false)
  @text.to_s
end

#validateObject

Notes never produce validation errors.



29
30
31
# File 'lib/charming/presentation/components/form/note.rb', line 29

def validate
  []
end