Text Input

Text inputs let users enter and edit text. Supports password toggle, search icon, validation states, masks, patterns, and length limits.

Usage Example
@textinput.TextInput(textinput.Config{
    ID:          "name",
    Name:        "name",
    Label:       "Name",
    Placeholder: "Enter your name",
})

Validation States

Set State to textinput.StateError or textinput.StateSuccess; the label, border, and HelperText recolor to match.

Error: Name field is required
Validation States
@textinput.TextInput(textinput.Config{
    ID: "email-error", Name: "email", Label: "Email",
    State: textinput.StateError, HelperText: "Error: Email is required",
})
@textinput.TextInput(textinput.Config{
    ID: "name-success", Name: "name", Label: "Name",
    State: textinput.StateSuccess, Value: "John",
})

Password Input

Type: textinput.TypePassword renders a built-in show/hide toggle button.

Password Input
@textinput.TextInput(textinput.Config{
    ID:           "password",
    Name:         "password",
    Label:        "Password",
    Type:         textinput.TypePassword,
    Placeholder:  "Enter your password",
    Autocomplete: "current-password",
})

Search Input

Type: textinput.TypeSearch adds a leading search icon.

Search Input
@textinput.TextInput(textinput.Config{
    Name:        "search",
    Type:        textinput.TypeSearch,
    Placeholder: "Search",
})

Input with Mask

Mask applies an Alpine.js x-mask pattern as the user types.

Input with Mask
@textinput.TextInput(textinput.Config{
    ID:           "phone",
    Name:         "phone",
    Label:        "Phone",
    Mask:         "(999) 999-9999",
    Placeholder:  "(999) 999-9999",
    Autocomplete: "tel-national",
})

Disabled Input

Disabled: true blocks editing and dims the field.

Disabled Input
@textinput.TextInput(textinput.Config{
    ID: "disabled", Name: "disabled", Label: "Disabled",
    Placeholder: "Cannot edit", Disabled: true,
})

Readonly Input

Readonly: true keeps the value submittable but non-editable.

Readonly Input
@textinput.TextInput(textinput.Config{
    ID: "readonly", Name: "readonly", Label: "Readonly",
    Value: "Cannot change this", Readonly: true,
})

Pattern Validation

Pattern sets the HTML pattern attribute; pair it with input events when you want live native-validity feedback.

Pattern Validation
@textinput.TextInput(textinput.Config{
    ID: "cluster", Name: "cluster_id", Label: "Cluster ID",
    Placeholder: "tabc123",
    Pattern:     "t[a-z0-9]{6}",
    InputAttrs: templ.Attributes{
        "x-on:input": "touched = true; valid = $event.target.checkValidity()",
        "x-on:blur":  "touched = true; valid = $event.target.checkValidity()",
        "x-bind:class": "touched ? (valid ? 'border-success' : 'border-danger') : ''",
        "x-bind:aria-invalid": "touched && !valid ? 'true' : 'false'",
        "aria-describedby": "patternInput-feedback",
    },
})

MaxLength

MaxLength caps the number of characters (0 = no limit).

MaxLength
@textinput.TextInput(textinput.Config{
    ID: "code", Name: "code", Label: "Code (max 7 chars)",
    Placeholder: "tabc123", MaxLength: 7,
})

API Reference

PropTypeDefaultDescription
IDstring""Unique id for the input (and the label's for target).
Namestring""Form field name.
Labelstring""Label text shown above the input.
Placeholderstring""Placeholder text when empty.
Valuestring""Current input value.
TypeInputTypeTypeTextInput type: "text", "password", "search", "email", "tel", "url", "number".
StateStateStateDefaultValidation state: "" (default), "error", "success".
HelperTextstring""Text below the input, recolored by State.
DisabledboolfalseDisables the input.
RequiredboolfalseMarks the input as required.
ReadonlyboolfalseNon-editable but still submittable.
Autocompletestring""HTML autocomplete attribute value.
Maskstring""Alpine.js x-mask pattern (e.g. "(999) 999-9999").
Patternstring""HTML pattern attribute for regex validation.
MaxLengthint0Character limit (0 = no limit).
InputAttrstempl.AttributesnilArbitrary attributes on the <input> (e.g. hx-post, hx-indicator).
RootClassstring""Extra classes on the container.