Class: Charming::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.



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

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.



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

def bind(state)
  @state = state
end

#focusable?Boolean

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

Returns:

  • (Boolean)


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

def focusable?
  false
end

#render(active: false) ⇒ Object

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



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

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

#validateObject

Notes never produce validation errors.



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

def validate
  []
end