struct TUI::Form::FieldSpec(M)

Overview

Declares one field of a Form::Host(M) form: its label, how to build the FormField that edits it, and how to read/write its value on the bound model M. #get/#set are required (no default) so a FieldSpec can never be constructed without a real binding to the model — this is the mechanism, not a convention, that rules out a field silently defaulting to a hardcoded value disconnected from whatever model it's supposedly editing.

#dropdown_options/#dropdown_multi opt a field out of the normal #build-a-FormField flow entirely — FormField's abstract contract has no side-channel for "please push a popup," so a field with #dropdown_options set is instead driven by Form::Host directly via TUI::DropdownPicker (see Form::Host#open_dropdown). #build is nilable and unused for dropdown fields.

Defined in:

tui/form/field_spec.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(label : String, get : M -> String, set : M, String -> Nil, build : -> FormField | Nil = nil, rows : Int32 = 1, validator : String -> Bool | Nil = nil, error_message : String = "Invalid value", dropdown_options : Array(FormEnumOption) | Nil = nil, dropdown_multi : Bool = false) #

[View source]

Instance Method Detail

def build : -> FormField | Nil #

def clone #

[View source]
def copy_with(label _label = @label, get _get = @get, set _set = @set, build _build = @build, rows _rows = @rows, validator _validator = @validator, error_message _error_message = @error_message, dropdown_options _dropdown_options = @dropdown_options, dropdown_multi _dropdown_multi = @dropdown_multi) #

[View source]
def dropdown_multi : Bool #

def dropdown_options : Array(FormEnumOption) | Nil #

def error_message : String #

def get : M -> String #

def label : String #

def rows : Int32 #

def set : M, String -> Nil #

def validator : String -> Bool | Nil #