uiForm

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 6 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.

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.

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). Number inputs accept InputNumberMin, InputNumberMax, and InputNumberStep.

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.

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"},
    },
})

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 when the field holds a value. The empty field shows the label as a placeholder.
  • 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"
)
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
	FocusRingColor               string
	IndeterminateOneWayStatePath string
	InputId                      string
	InputName                    string
	IsChecked                    bool
	IsCheckedOneWayStatePath     string
	IsDisabled                   bool
	IsDisabledOneWayStatePath    string
	IsRequired                   bool
	Label                        string
	LabelPosition                string
	OnChangeFunc                 string
	Shape                        string
	Size                         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
}

type InputFieldSettings

type InputFieldSettings struct {
	InputType string
	InputName string
	Label     string

	// OptionalFields
	TwoWayStatePath                   string
	Value                             string
	AffixLeftValue                    string
	AffixLeftStatePath                string
	AffixRightValue                   string
	AffixRightStatePath               string
	InputId                           string
	InputNumberMin                    string
	InputNumberMax                    string
	InputNumberStep                   string
	IsRequired                        bool
	IsReadOnly                        bool
	HintValue                         string
	HintStatePath                     string
	HintDisplay                       string
	HintDisplayTooltipBackgroundColor string
	HintIconStyle                     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
	DropdownBackgroundColor           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
}

type SelectInputSettings

type SelectInputSettings struct {
	InputName string
	Label     string

	// OptionalFields
	FlatOptions                       []string
	LabelValueOptions                 []SelectLabelValueOption
	TwoWayStatePath                   string
	OnChangeFunc                      string
	Size                              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
	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
	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