Skip to main content

Time Input

TimeInput lets users pick a time of day using a clock‑style picker. It returns a *time.Time whose date part is zeroed (00‑01‑01) and whose location is whatever you pass in WithLocation (defaults to time.Local).

Signature

t := ui.TimeInput(label string, opts ...timeinput.Option) *time.Time

t is nil until the user chooses a value.

Option helpers

HelperPurposeDefault
timeinput.WithPlaceholder("HH:mm")Placeholder when empty.""
timeinput.WithDefaultValue(time.Now())Pre‑fill on first render.nil
timeinput.WithRequired(true)Inside a Form blocks submit until a value is chosen.false
timeinput.WithDisabled(true)Makes the field read‑only.false
timeinput.WithLocation(time.UTC)Time‑zone used for parsing and formatting.time.Local

Behaviour notes

  • Storage – backend saves the value in session; subsequent reruns keep the last input.
  • Format – the widget always serialises as HH:MM:SS (Go’s time.TimeOnly). There is no custom format option.
  • Time‑zone – if you care about absolute moments in time, apply the same Location when comparing with other timestamps.

Examples

Basic picker

start := ui.TimeInput("Start time")
if start != nil {
fmt.Println("selected:", start.Format(time.TimeOnly))
}

Pre‑selected, disabled

ui.TimeInput("Closing time",
timeinput.WithDefaultValue(time.Date(0,0,0,18,0,0,0,time.Local)),
timeinput.WithDisabled(true),
)

Required inside a form

f, submitted := ui.Form("Save")
when := f.TimeInput("Reminder", timeinput.WithRequired(true))
if submitted {
scheduleReminder(*when)
}