Combobox

Client-mode comboboxes toggle entirely in the browser (no HTTP on open/select); server-mode keeps an HTMX lazy/search path for options that can't be pre-rendered.

  • Technology
  • Healthcare
  • Finance
  • Retail
  • Education
Usage Example
// Client mode: options are pre-rendered, toggling happens in the browser.
var IndustryCfg = combobox.Config{
    ID: "industry", Name: "industry", Label: "Industry",
    Mode:   combobox.ModeSingle,
    Source: combobox.Source{Static: industryOptions},
}
@combobox.Combobox(IndustryCfg, combobox.State{Options: IndustryCfg.Source.Static})

Client Multi-Select

Mode: combobox.ModeMultiple with EnableClearAll — still fully client-side.

  • Go
  • Rust
  • TypeScript
  • Python
  • Kotlin
Client Multi-Select
var SkillsCfg = combobox.Config{
    ID: "skills", Name: "skills", Mode: combobox.ModeMultiple, EnableClearAll: true,
    Source: combobox.Source{Static: skillOptions},
}
@combobox.Combobox(SkillsCfg, combobox.State{Options: SkillsCfg.Source.Static})

Selected and Disabled Options

Set Config.Selected for first-paint values. Disabled options stay visible but cannot be selected.

  • US East
  • EU West
  • AP South
  • Legacy region
Selected and Disabled Options
var RegionsCfg = combobox.Config{
    ID: "region", Name: "region", Label: "Region",
    Selected: []string{"us-east-1"},
    Source: combobox.Source{Static: []combobox.Option{
        {Value: "us-east-1", Label: "US East"},
        {Value: "legacy", Label: "Legacy region", Disabled: true},
    }},
}
@combobox.Combobox(RegionsCfg, RegionsCfg.InitialState())

Set the Toggle/Options/Clear endpoints and a LazyEndpoint Source; the component fetches and searches options over HTMX.

  • No matches found
Server Mode (lazy search)
var UsersCfg = combobox.Config{
    ID: "users", Name: "users", Mode: combobox.ModeMultiple,
    EnableSearch: true, EnableClearAll: true,
    ToggleEndpoint:  "/api/.../toggle",
    OptionsEndpoint: "/api/.../options",
    ClearEndpoint:   "/api/.../clear",
    Source: combobox.Source{LazyEndpoint: "/api/.../options"},
}
@combobox.Combobox(UsersCfg, combobox.State{})

Cascading Server Filters

DependsOn adds other fields to combobox HTMX requests. Add an hx-get on the parent field when changing it should immediately refresh the dependent options.

  • No matches found
Cascading Server Filters
selectedProvider := "aws"
var ClusterCfg = combobox.Config{
    ID: "cluster", Name: "cluster", Mode: combobox.ModeSingle,
    EnableSearch: true,
    DependsOn: []string{"provider"},
    ToggleEndpoint:  "/api/.../clusters/toggle",
    OptionsEndpoint: "/api/.../clusters/options",
    ClearEndpoint:   "/api/.../clusters/clear",
    Source: combobox.Source{LazyEndpoint: "/api/.../clusters/options"},
}

// OptionsProvider receives search and deps["provider"] on the server.
clustersProvider := func(ctx context.Context, search string, deps map[string]string) ([]combobox.Option, error) {
    return clustersForProvider(deps["provider"], search)
}

<select
    name="provider"
    hx-get={ ClusterCfg.OptionsEndpoint }
    hx-trigger="change"
    hx-target="#cluster-options"
    hx-swap="outerHTML"
    hx-include="#cluster [data-combobox-search], #cluster input[type=hidden]">
    <option value={ selectedProvider }>AWS</option>
</select>
@combobox.Combobox(ClusterCfg, combobox.State{})

API Reference

PropTypeDefaultDescription
IDstring""Unique id (seeds #<id>-trigger, options, hidden inputs).
Namestring""Form field name (multi-select submits repeated hidden inputs).
Labelstring""Label above the combobox.
Placeholderstring""Trigger placeholder.
ModeModeModeSinglecombobox.ModeSingle or combobox.ModeMultiple.
Source.Static[]OptionnilClient-mode options rendered into the first page. Use InitialState() to pass them into State.
Source.LazyEndpointstring""Server-mode endpoint used for first load/search. Cannot be combined with Source.Static.
Optionstruct-Option row fields: Value, Label, Disabled. Meta, Img, Initials, Badge, and BadgeColor are data-model fields not rendered by the current list template.
Selected[]stringnilInitial selected values for first-paint/static renders.
State.Options[]OptionnilOptions available for this render. Client mode usually uses cfg.InitialState().
State.Selected[]stringnilSelected values for this render; server handlers return updated Body/OptionsList state.
State.Searchstring""Current server-side search term used when rendering filtered results.
OptionsProviderfuncnilServer helper shape: func(ctx, search, deps) ([]combobox.Option, error).
EnableSearchboolfalseShow a search box (server mode queries the endpoint).
EnableClearAllboolfalseShow a clear-all action.
RequiredboolfalseMark the field required.
DependsOn[]stringnilOther field names included in server HTMX requests via hx-include.
ToggleEndpointstring""Server URL for toggling a selection (server mode).
OptionsEndpointstring""Server URL for fetching/searching options.
ClearEndpointstring""Server URL for clearing the selection.
DisabledboolfalseDisable interaction.
RootClassstring""Extra classes on the container.