Documentation
¶
Overview ¶
Package forms provides reusable form components for editing GCP resources. It includes FormField (individual inputs), FormSection (field groups), and FormView (complete forms with navigation and validation).
Index ¶
- func ValidateAll(validators ...Validator) func(value any) []error
- func ValidateGCPLabelKey(value any) error
- func ValidateGCPLabelValue(value any) error
- func ValidateGCPResourceName(value any) error
- func ValidateGCSBucketName(value any) error
- func ValidateNotEmpty(value any) error
- func ValidateRequired(value any) error
- type Component
- type Field
- func NewDropdownField(id, label string) *Field
- func NewField(id, label string, fieldType FieldType) *Field
- func NewMultiSelectField(id, label string) *Field
- func NewNumberField(id, label string) *Field
- func NewReadOnlyField(id, label string, value string) *Field
- func NewTextAreaField(id, label string) *Field
- func NewTextField(id, label string) *Field
- func NewToggleField(id, label string) *Field
- func (f *Field) Blur()
- func (f *Field) EstimatedHeight() int
- func (f *Field) Focus()
- func (f *Field) GetStringValue() string
- func (f *Field) GetValue() any
- func (f *Field) HasError() bool
- func (f *Field) IsDirty() bool
- func (f *Field) IsEditable() bool
- func (f *Field) IsFocused() bool
- func (f *Field) IsTextInput() bool
- func (f *Field) SetCharLimit(limit int) *Field
- func (f *Field) SetHelpText(text string) *Field
- func (f *Field) SetHidden(hidden bool) *Field
- func (f *Field) SetOptions(options []Option) *Field
- func (f *Field) SetOptionsFromStrings(values []string) *Field
- func (f *Field) SetPlaceholder(placeholder string) *Field
- func (f *Field) SetRequired(required bool) *Field
- func (f *Field) SetRows(rows int) *Field
- func (f *Field) SetShowLineNumbers(show bool) *Field
- func (f *Field) SetSize(width, height int)
- func (f *Field) SetValidator(validator Validator) *Field
- func (f *Field) SetValue(value any) *Field
- func (f *Field) Update(msg tea.Msg) tea.Cmd
- func (f *Field) Validate() error
- func (f *Field) View() string
- type FieldChangedMsg
- type FieldType
- type Form
- func (f *Form) AddSection(section *Section) *Form
- func (f *Form) EnableViewport() *Form
- func (f *Form) Focus()
- func (f *Form) FocusedSection() *Section
- func (f *Form) GetData() map[string]interface{}
- func (f *Form) GetField(id string) *Field
- func (f *Form) GetSection(id string) *Section
- func (f *Form) HasErrors() bool
- func (f *Form) HasTextInputFocused() bool
- func (f *Form) Init() tea.Cmd
- func (f *Form) IsDirty() bool
- func (f *Form) SectionCount() int
- func (f *Form) Sections() []*Section
- func (f *Form) SetData(data map[string]interface{})
- func (f *Form) SetSize(width, height int)
- func (f *Form) SetSubtitle(subtitle string) *Form
- func (f *Form) ShortHelp() string
- func (f *Form) Update(msg tea.Msg) tea.Cmd
- func (f *Form) Validate() []string
- func (f *Form) View() string
- type FormCancelMsg
- type FormMode
- type FormSubmitMsg
- type Option
- type Section
- func (s *Section) AddField(field *Field) *Section
- func (s *Section) Blur()
- func (s *Section) EditableFieldCount() int
- func (s *Section) FieldCount() int
- func (s *Section) Fields() []*Field
- func (s *Section) Focus()
- func (s *Section) FocusFirstEditable() bool
- func (s *Section) FocusLastEditable() bool
- func (s *Section) FocusedField() *Field
- func (s *Section) FocusedFieldIndex() int
- func (s *Section) GetData() map[string]interface{}
- func (s *Section) GetField(id string) *Field
- func (s *Section) HasErrors() bool
- func (s *Section) HasTextInputFocused() bool
- func (s *Section) IsDirty() bool
- func (s *Section) IsFocused() bool
- func (s *Section) NextField() bool
- func (s *Section) PrevField() bool
- func (s *Section) SetCollapsed(collapsed bool) *Section
- func (s *Section) SetCollapsible(collapsible bool) *Section
- func (s *Section) SetDescription(desc string) *Section
- func (s *Section) SetIcon(icon string) *Section
- func (s *Section) SetSize(width, height int)
- func (s *Section) ToggleCollapse()
- func (s *Section) Update(msg tea.Msg) tea.Cmd
- func (s *Section) Validate() []error
- func (s *Section) View() string
- type ValidationErrorMsg
- type Validator
- func ComposeValidators(validators ...Validator) Validator
- func ConditionalValidator(condition func(value any) bool, validator Validator) Validator
- func ValidateCIDR() Validator
- func ValidateDiskSize(minGB, maxGB int64) Validator
- func ValidateEmail() Validator
- func ValidateIPAddress() Validator
- func ValidateNotOneOf(disallowed []string, errorMsg string) Validator
- func ValidateNumber(min, max int64) Validator
- func ValidateOneOf(allowed []string) Validator
- func ValidatePattern(pattern string, errorMsg string) Validator
- func ValidateStringLength(min, max int) Validator
- func ValidateURL() Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateAll ¶
ValidateAll runs all validators and collects all errors
func ValidateGCPLabelKey ¶
ValidateGCPLabelKey validates a GCP label key
func ValidateGCPLabelValue ¶
ValidateGCPLabelValue validates a GCP label value
func ValidateGCPResourceName ¶
ValidateGCPResourceName validates a GCP resource name
func ValidateGCSBucketName ¶
ValidateGCSBucketName validates a GCS bucket name according to GCP rules
func ValidateNotEmpty ¶
ValidateNotEmpty is a simpler alias for ValidateRequired
func ValidateRequired ¶
ValidateRequired returns an error if the value is empty
Types ¶
type Field ¶
type Field struct {
// Configuration
ID string
Label string
Type FieldType
Required bool
HelpText string
Placeholder string
Validator Validator
// Options for dropdown/multiselect
Options []Option
// Visibility
Hidden bool // When true, field is not rendered, not validated, not navigable
// contains filtered or unexported fields
}
Field represents a single form input field
func NewDropdownField ¶
NewDropdownField creates a dropdown selection field
func NewMultiSelectField ¶
NewMultiSelectField creates a multi-selection field
func NewNumberField ¶
NewNumberField creates a numeric input field
func NewReadOnlyField ¶
NewReadOnlyField creates a read-only display field
func NewTextAreaField ¶
NewTextAreaField creates a multi-line text input field
func NewTextField ¶
NewTextField creates a text input field
func NewToggleField ¶
NewToggleField creates a boolean toggle field
func (*Field) EstimatedHeight ¶
EstimatedHeight returns the approximate number of lines this field occupies. Used by scrollToFocused to calculate viewport offsets.
func (*Field) GetStringValue ¶
GetStringValue returns the field value as a string
func (*Field) IsEditable ¶
IsEditable returns true if the field can be edited
func (*Field) IsTextInput ¶
IsTextInput returns true if this field accepts free text input (and thus should capture character keys instead of letting them be handled globally)
func (*Field) SetCharLimit ¶
SetCharLimit sets the character limit for text input
func (*Field) SetHelpText ¶
SetHelpText sets the help text shown below the field
func (*Field) SetHidden ¶
SetHidden controls whether this field is rendered, validated, or navigable.
func (*Field) SetOptions ¶
SetOptions sets the available options for dropdown/multiselect fields. Clamps selectedIndex and scroll offset to prevent out-of-bounds access.
func (*Field) SetOptionsFromStrings ¶
SetOptionsFromStrings creates options from simple string values. Clamps selectedIndex and scroll offset to prevent out-of-bounds access.
func (*Field) SetPlaceholder ¶
SetPlaceholder sets the placeholder text for text/number/textarea fields
func (*Field) SetRequired ¶
SetRequired marks the field as required
func (*Field) SetShowLineNumbers ¶
SetShowLineNumbers enables or disables line numbers for textarea
func (*Field) SetValidator ¶
SetValidator sets the validation function for the field
type FieldChangedMsg ¶
FieldChangedMsg is sent when a field value changes
type FieldType ¶
type FieldType int
FieldType defines the type of input for a form field
const ( // FieldText is a single-line text input FieldText FieldType = iota // FieldNumber is a numeric input with optional min/max validation FieldNumber // FieldDropdown is a single selection from options FieldDropdown // FieldMultiSelect allows multiple selections FieldMultiSelect // FieldToggle is a boolean on/off switch FieldToggle // FieldReadOnly displays a value without allowing edits FieldReadOnly // FieldTextArea is a multi-line text input FieldTextArea )
type Form ¶
type Form struct {
// Configuration
Title string
Subtitle string
Mode FormMode
// contains filtered or unexported fields
}
Form represents a complete form with multiple sections
func (*Form) AddSection ¶
AddSection adds a section to the form
func (*Form) EnableViewport ¶
EnableViewport enables viewport scrolling for long forms
func (*Form) FocusedSection ¶
FocusedSection returns the currently focused section
func (*Form) GetSection ¶
GetSection returns a section by ID
func (*Form) HasTextInputFocused ¶
HasTextInputFocused returns true if a text input field is currently focused. This is used by the app to know whether to consume character keys or pass them to global handlers (e.g., "q" for quit).
func (*Form) SectionCount ¶
SectionCount returns the number of sections
func (*Form) SetSubtitle ¶
SetSubtitle sets the form subtitle
type FormCancelMsg ¶
type FormCancelMsg struct{}
FormCancelMsg is sent when the form is canceled via Esc
type FormMode ¶
type FormMode int
FormMode defines whether a form is for creating, editing, or cloning
type FormSubmitMsg ¶
FormSubmitMsg is sent when the form is submitted via Ctrl+S
type Option ¶
type Option struct {
Value string // Internal value used for data
Label string // Display label shown to user
Description string // Optional description shown on hover/focus
}
Option represents a selectable option in dropdown/multiselect fields
type Section ¶
type Section struct {
// Configuration
ID string
Title string
Icon string
Description string
Collapsible bool
Collapsed bool
// contains filtered or unexported fields
}
Section represents a group of related form fields
func (*Section) EditableFieldCount ¶
EditableFieldCount returns the number of editable fields
func (*Section) FieldCount ¶
FieldCount returns the number of fields
func (*Section) FocusFirstEditable ¶
FocusFirstEditable focuses the first editable field
func (*Section) FocusLastEditable ¶
FocusLastEditable focuses the last editable field
func (*Section) FocusedField ¶
FocusedField returns the currently focused field
func (*Section) FocusedFieldIndex ¶
FocusedFieldIndex returns the index of the focused field
func (*Section) HasTextInputFocused ¶
HasTextInputFocused returns true if a text input field is currently focused
func (*Section) NextField ¶
NextField moves focus to the next editable field Returns true if focus moved within section, false if at end
func (*Section) PrevField ¶
PrevField moves focus to the previous editable field Returns true if focus moved within section, false if at start
func (*Section) SetCollapsed ¶
SetCollapsed sets the initial collapsed state
func (*Section) SetCollapsible ¶
SetCollapsible makes the section collapsible
func (*Section) SetDescription ¶
SetDescription sets the section description
func (*Section) ToggleCollapse ¶
func (s *Section) ToggleCollapse()
ToggleCollapse toggles the collapsed state
type ValidationErrorMsg ¶
ValidationErrorMsg is sent when validation fails
type Validator ¶
Validator is a function that validates a field value. It returns nil if the value is valid, or an error describing the issue.
func ComposeValidators ¶
ComposeValidators chains multiple validators together All validators run, and the first error is returned
func ConditionalValidator ¶
ConditionalValidator runs a validator only if a condition is met
func ValidateCIDR ¶
func ValidateCIDR() Validator
ValidateCIDR returns a validator for CIDR notation (e.g., 10.0.0.0/8)
func ValidateDiskSize ¶
ValidateDiskSize validates a disk size value (GCP constraints)
func ValidateEmail ¶
func ValidateEmail() Validator
ValidateEmail returns a validator for email addresses
func ValidateIPAddress ¶
func ValidateIPAddress() Validator
ValidateIPAddress returns a validator for IPv4 addresses
func ValidateNotOneOf ¶
ValidateNotOneOf returns a validator that checks if value is NOT one of disallowed values
func ValidateNumber ¶
ValidateNumber returns a validator that checks if a number is within a range
func ValidateOneOf ¶
ValidateOneOf returns a validator that checks if value is one of allowed values
func ValidatePattern ¶
ValidatePattern returns a validator that checks against a regex pattern
func ValidateStringLength ¶
ValidateStringLength returns a validator that checks string length