uiForm

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 7 Imported by: 1

README

Form

Form layer of Infinite UI. It collects user input: text, choices, and switches. Every component binds to Alpine.js state; field components render their label as a floating legend. Part of Infinite UI.

Every labelled form component accepts TextCase with a uiToolset.TextCase* value: TextCaseNone (the default, as typed), TextCaseLower, TextCaseUpper, or TextCaseCapitalize. It transforms the label, and the placeholder where the component renders one.

CheckboxInput

Checkbox with a label, bound to a boolean or an array state path.

@uiForm.CheckboxInput(uiForm.CheckboxInputSettings{
    Label:           "Accept the terms",
    TwoWayStatePath: "hasAcceptedTerms",

    // OptionalFields
    InputName: "hasAcceptedTerms",
    Shape:     uiForm.CheckboxInputShapeRounded,
})

Shape accepts CheckboxInputShapeSquare, CheckboxInputShapeRounded (the default), and CheckboxInputShapeCircular. Size accepts the CheckboxInputSize* constants. CheckedColor, UncheckedColor, and FocusRingColor set the box colors. LabelPosition accepts CheckboxInputLabelPositionLeft and CheckboxInputLabelPositionRight. IsChecked, IsDisabled, and IsRequired render static states; IsCheckedOneWayStatePath, IsDisabledOneWayStatePath, and IndeterminateOneWayStatePath bind them to Alpine state. AriaLabel names the checkbox when no visible label is present.

IsInvalid and IsInvalidOneWayStatePath flag the error state: the box border turns to ErrorColor (default "red-500"), and the input carries aria-invalid. ErrorMessage and ErrorMessageOneWayStatePath render the message below the control; with InputId set, the input links to it through aria-describedby. When an invalid path is set, the message shows only while the path is true.

InputField

Single-line input with a floating label, optional affixes, and an optional hint.

@uiForm.InputField(uiForm.InputFieldSettings{
    InputType:       uiForm.InputTypeText,
    InputName:       "name",
    Label:           "Name",
    TwoWayStatePath: "name",
    IsRequired:      true,
})

InputType accepts the uiForm.InputType* constants. An affix renders a static value (AffixLeftValue, AffixRightValue) or binds a state path (AffixLeftStatePath, AffixRightStatePath). Set AffixLeftWidthPercent or AffixRightWidthPercent to fix an affix to a percentage of the field width, for example 25 or 50. Number inputs accept InputNumberMin, InputNumberMax, and InputNumberStep. Size accepts the InputFieldSize* constants and defaults to md; it scales the input, the affixes, and the floating label together. TextCase accepts a uiToolset.TextCase* value; it transforms the floating label and the placeholder. The default, TextCaseNone, leaves the text as typed.

TextArea

Multiline input with expand, copy, and clear actions.

@uiForm.TextArea(uiForm.TextAreaSettings{
    Label:           "Description",
    TwoWayStatePath: "description",
})

Set IsCode for monospace text. IsReadOnly sets the native readonly attribute. IsRequired adds the required marker to the label.

SelectInput

Dropdown select. It is not a native <select>: screen-reader-only radio inputs and an Alpine-driven list carry the value. Three option modes exist:

  1. FlatOptions []string for plain values.
  2. LabelValueOptions []SelectLabelValueOption for label and value pairs.
  3. LabelValueOptions with LabelHtml for rich option content.
@uiForm.SelectInput(uiForm.SelectInputSettings{
    InputName:       "status",
    Label:           "Status",
    FlatOptions:     []string{"running", "stopped"},
    TwoWayStatePath: "status",
})

ShouldIncludeBlankOption adds a clear entry. IsDisabledOneWayStatePath disables the trigger while the path is truthy. OnChangeFunc runs after a change. Size accepts the SelectInputSize* constants and defaults to md.

MultiSelectInput

Dropdown that holds a list of selected values on one state path.

@uiForm.MultiSelectInput(uiForm.MultiSelectInputSettings{
    InputName:       "countries",
    Label:           "Countries",
    FlatOptions:     []string{"Argentina", "Brazil", "Chile"},
    TwoWayStatePath: "countries",
})

It shares the FlatOptions and LabelValueOptions modes with SelectInput. OnChangeFunc runs after a checkbox toggle or a clear.

RadioInput

Single radio option. Group several inputs by sharing one TwoWayStatePath.

@uiForm.RadioInput(uiForm.RadioInputSettings{
    Label:           "Option 1",
    StateValue:      "option1",
    TwoWayStatePath: "selectedOption",
})

InlineRadioGroup

A row of radios with one shared label.

@uiForm.InlineRadioGroup(uiForm.InlineRadioGroupSettings{
    Label: "Select an option",
    InputSettings: []uiForm.RadioInputSettings{
        {Label: "Option 1", StateValue: "option1", TwoWayStatePath: "groupSelection"},
        {Label: "Option 2", StateValue: "option2", TwoWayStatePath: "groupSelection"},
    },
})

InlineRadioGroup's TextCase transforms only the shared label. Each option label takes its own RadioInputSettings.TextCase.

ToggleSwitch

Boolean switch. Bind one state path, or set CustomValue to collect one value into an array state path.

@uiForm.ToggleSwitch(uiForm.ToggleSwitchSettings{
    Label:           "Enable notifications",
    TwoWayStatePath: "isNotificationsEnabled",
})

LabelPosition accepts ToggleSwitchLabelPositionLeft and ToggleSwitchLabelPositionRight. The *Color settings override the track and thumb colors.

InputHint

Shared hint helper for the fields above. It renders no field of its own.

  • HintDisplay accepts InputHintDisplayTooltip for an icon with a tooltip, or InputHintDisplayDescription for a line below the field.
  • HintValue carries static text; HintStatePath binds live text.
  • InputHintTooltip and InputHintDescription can also render directly, when a hint sits next to custom markup.

Non-obvious behaviors

  • SelectInput and MultiSelectInput render a templ.JSONScript block for label-value options. The block feeds the selected label lookup.
  • The floating legend collapses while the field is empty, so the empty field shows the label as a placeholder.
  • InputField hides its empty legend with display: none. Chrome reserves scroll space for a zero-sized legend, so the opacity-based collapse the other field components use can phantom-scroll an overflow container.
  • A SelectInput dropdown opens upward when it would overflow the bottom of the viewport.
  • InputName sets the key in an HTMX form submission. InputId is optional.

Documentation

Overview

templ: version: v0.3.1020

templ: version: v0.3.1020

templ: version: v0.3.1020

templ: version: v0.3.1020

templ: version: v0.3.1020

templ: version: v0.3.1020

templ: version: v0.3.1020

templ: version: v0.3.1020

templ: version: v0.3.1020

Index

Constants

View Source
const (
	CheckboxInputShapeSquare   string = "square"
	CheckboxInputShapeRounded  string = "rounded"
	CheckboxInputShapeCircular string = "circular"

	CheckboxInputSizeXs string = "xs"
	CheckboxInputSizeSm string = "sm"
	CheckboxInputSizeMd string = "md"
	CheckboxInputSizeLg string = "lg"
	CheckboxInputSizeXl string = "xl"

	CheckboxInputLabelPositionLeft  string = "left"
	CheckboxInputLabelPositionRight string = "right"
)
View Source
const (
	InputTypeColor    string = "color"
	InputTypeDate     string = "date"
	InputTypeEmail    string = "email"
	InputTypeHidden   string = "hidden"
	InputTypeMonth    string = "month"
	InputTypeNumber   string = "number"
	InputTypePassword string = "password"
	InputTypeTel      string = "tel"
	InputTypeText     string = "text"
	InputTypeTime     string = "time"
	InputTypeUrl      string = "url"

	InputFieldSizeXs string = "xs"
	InputFieldSizeSm string = "sm"
	InputFieldSizeMd string = "md"
	InputFieldSizeLg string = "lg"
	InputFieldSizeXl string = "xl"
)
View Source
const (
	InputHintDisplayTooltip     string = "tooltip"
	InputHintDisplayDescription string = "description"

	InputHintSizeSm string = "sm"
	InputHintSizeLg string = "lg"

	InputHintIconStylePlain string = "plain"
	InputHintIconStyleBoxed string = "boxed"
)
View Source
const (
	RadioInputSizeXs string = "xs"
	RadioInputSizeSm string = "sm"
	RadioInputSizeMd string = "md"
	RadioInputSizeLg string = "lg"
	RadioInputSizeXl string = "xl"
)
View Source
const (
	SelectInputSizeXs string = "xs"
	SelectInputSizeSm string = "sm"
	SelectInputSizeMd string = "md"
	SelectInputSizeLg string = "lg"
	SelectInputSizeXl string = "xl"
)
View Source
const (
	TextAreaSizeXs = "xs"
	TextAreaSizeSm = "sm"
	TextAreaSizeMd = "md"
	TextAreaSizeLg = "lg"
	TextAreaSizeXl = "xl"
)
View Source
const (
	ToggleSwitchLabelPositionLeft  string = "left"
	ToggleSwitchLabelPositionRight string = "right"
	ToggleSwitchSizeXs             string = "xs"
	ToggleSwitchSizeSm             string = "sm"
	ToggleSwitchSizeMd             string = "md"
	ToggleSwitchSizeLg             string = "lg"
	ToggleSwitchSizeXl             string = "xl"
)

Variables

This section is empty.

Functions

func CheckboxInput added in v0.2.1

func CheckboxInput(componentSettings CheckboxInputSettings) templ.Component

func InlineRadioGroup

func InlineRadioGroup(componentSettings InlineRadioGroupSettings) templ.Component

func InputField

func InputField(componentSettings InputFieldSettings) templ.Component

func InputHintDescription added in v0.2.0

func InputHintDescription(componentSettings InputHintSettings) templ.Component

func InputHintTooltip added in v0.2.0

func InputHintTooltip(componentSettings InputHintSettings) templ.Component

func MultiSelectInput added in v0.1.7

func MultiSelectInput(componentSettings MultiSelectInputSettings) templ.Component

func RadioInput

func RadioInput(componentSettings RadioInputSettings) templ.Component

func SelectInput

func SelectInput(componentSettings SelectInputSettings) templ.Component

func TextArea

func TextArea(componentSettings TextAreaSettings) templ.Component

func ToggleSwitch added in v0.1.8

func ToggleSwitch(componentSettings ToggleSwitchSettings) templ.Component

ToggleSwitch supports two Alpine.js binding modes:

Boolean mode: Set TwoWayStatePath to a boolean property and leave CustomValue empty. Example: x-data="{enabled: false}", TwoWayStatePath: "enabled".

Array mode: Set TwoWayStatePath to an array property and set CustomValue to one item. Alpine.js adds the value when checked and removes it when unchecked. Render one switch for each item, using the same path and a different value. Example: x-data="{channels: ['email']}", TwoWayStatePath: "channels", CustomValue: "sms".

Set InputName to include the bound state in form submission.

Types

type CheckboxInputSettings added in v0.2.1

type CheckboxInputSettings struct {
	// OptionalFields
	AriaLabel                    string
	CheckedColor                 string
	ErrorColor                   string
	ErrorMessage                 string
	ErrorMessageOneWayStatePath  string
	FocusRingColor               string
	IndeterminateOneWayStatePath string
	InputId                      string
	InputName                    string
	IsChecked                    bool
	IsCheckedOneWayStatePath     string
	IsDisabled                   bool
	IsDisabledOneWayStatePath    string
	IsInvalid                    bool
	IsInvalidOneWayStatePath     string
	IsRequired                   bool
	Label                        string
	LabelPosition                string
	OnChangeFunc                 string
	Shape                        string
	Size                         string
	TextCase                     string
	TextColor                    string
	TwoWayStatePath              string
	UncheckedColor               string
	Value                        string
}

type InlineRadioGroupSettings

type InlineRadioGroupSettings struct {
	Label         string
	InputSettings []RadioInputSettings

	// OptionalFields
	TwoWayStatePath string
	InputId         string
	InputName       string
	TextCase        string
}

type InputFieldSettings

type InputFieldSettings struct {
	InputType string
	InputName string
	Label     string

	// OptionalFields
	TwoWayStatePath                   string
	Value                             string
	AffixLeftValue                    string
	AffixLeftStatePath                string
	AffixLeftWidthPercent             uint
	AffixRightValue                   string
	AffixRightStatePath               string
	AffixRightWidthPercent            uint
	InputId                           string
	InputNumberMin                    string
	InputNumberMax                    string
	InputNumberStep                   string
	IsRequired                        bool
	IsReadOnly                        bool
	TextCase                          string
	HintValue                         string
	HintStatePath                     string
	HintDisplay                       string
	HintDisplayTooltipBackgroundColor string
	HintIconStyle                     string
	Size                              string
}

type InputHintSettings added in v0.2.0

type InputHintSettings struct {
	Value                  string
	StatePath              string
	TooltipBackgroundColor string
	Size                   string
	IconStyle              string
}

type MultiSelectInputSettings added in v0.1.7

type MultiSelectInputSettings struct {
	InputName string
	Label     string

	// OptionalFields
	FlatOptions                       []string
	LabelValueOptions                 []SelectLabelValueOption
	TwoWayStatePath                   string
	InputId                           string
	IsRequired                        bool
	OnChangeFunc                      string
	DropdownBackgroundColor           string
	TextCase                          string
	HintValue                         string
	HintStatePath                     string
	HintDisplay                       string
	HintDisplayTooltipBackgroundColor string
	HintIconStyle                     string
}

type RadioInputSettings

type RadioInputSettings struct {
	Label           string
	StateValue      string
	TwoWayStatePath string

	// OptionalFields
	InputId   string
	InputName string
	Size      string
	TextCase  string
}

type SelectInputSettings

type SelectInputSettings struct {
	InputName string
	Label     string

	// OptionalFields
	FlatOptions                       []string
	LabelValueOptions                 []SelectLabelValueOption
	TwoWayStatePath                   string
	OnChangeFunc                      string
	Size                              string
	TextCase                          string
	DropdownBackgroundColor           string
	IsDisabledOneWayStatePath         string
	IsRequired                        bool
	ShouldIncludeBlankOption          bool
	HintValue                         string
	HintStatePath                     string
	HintDisplay                       string
	HintDisplayTooltipBackgroundColor string
	HintIconStyle                     string
}

type SelectLabelValueOption

type SelectLabelValueOption struct {
	Label     string          `json:"label"`
	LabelHtml templ.Component `json:"-"`
	Value     string          `json:"value"`
}

type TextAreaSettings

type TextAreaSettings struct {
	Label string

	// OptionalFields
	InputId                           string
	InputName                         string
	Size                              string
	TextCase                          string
	TwoWayStatePath                   string
	Value                             string
	IsCode                            bool
	IsReadOnly                        bool
	IsRequired                        bool
	HintValue                         string
	HintStatePath                     string
	HintDisplay                       string
	HintDisplayTooltipBackgroundColor string
}

type ToggleSwitchSettings added in v0.1.8

type ToggleSwitchSettings struct {
	Label           string
	TwoWayStatePath string

	// OptionalFields
	CustomValue                 string
	FocusRingColor              string
	InputId                     string
	InputName                   string
	IsDisabled                  bool
	IsRequired                  bool
	LabelPosition               string
	Size                        string
	TextCase                    string
	TextColor                   string
	ThumbBackgroundColor        string
	ThumbBorderColor            string
	TrackBackgroundColor        string
	TrackCheckedBackgroundColor string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL