LanternUI.Components.DatetimeField (LanternUI v0.3.3)

Copy Markdown View Source

A segmented, directly-editable date/time field — the trigger primitive the date pickers compose (HeroUI-style: 2 / 3 / 2026, 8:45 AM).

<.datetime_field id="due" name="due" mode={:date} value="2026-02-03" />
<.datetime_field id="at" name="at" mode={:datetime} precision={:millisecond} value={nil} />

Each segment (month/day/year/hour/minute/…) is individually editable: type digits, step with ↑/↓ (wrapping), move with ←/→, clear with Backspace — driven by the LanternDatetimeField hook, DOM-local.

Value contract (critical — lantern's Coercion depends on it)

A hidden <input name> carries the canonical value; the segments are display sugar. Canonical strings per mode:

  • :dateYYYY-MM-DD
  • :timeHH:MM:SS.mmm (24h)
  • :datetimeYYYY-MM-DDTHH:MM:SS.mmm

An empty hidden value means null (SQL NULL for lantern). Display shows a 12-hour clock with AM/PM; the canonical value is always 24h.

precision controls which time segments are shown/edited: :minute (default), :second, or :millisecond. Unshown parts are carried as zeros in the canonical value, so ms precision survives even at :minute display.

Summary

Functions

datetime_field(assigns)

Attributes

  • id (:string) (required)
  • name (:string) - omit for a non-submitting field (no name on the hidden input). Defaults to nil.
  • mode (:atom) - Defaults to :date. Must be one of :date, :time, or :datetime.
  • precision (:atom) - Defaults to :minute. Must be one of :minute, :second, or :millisecond.
  • value (:any) - canonical string (see value contract) or nil. Defaults to nil.
  • nullable (:boolean) - Defaults to true.
  • disabled (:boolean) - Defaults to false.
  • form (:string) - the form attribute forwarded to the hidden input. Defaults to nil.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • suffix - trailing affix inside the field (e.g. the picker's toggle button).