Date picker
NewOverview
A date picker wrapping a minimalist JS library.
<.form
for={@date_form}
id="example-date-form"
phx-change="validate-date"
phx-submit="save-date"
class="grid w-full max-w-sm gap-4"
>
<DatePicker.date_picker
field={@date_form[:starts_on]}
label="Start date"
sublabel="2026 only"
description="Choose a date in 2026."
min={~D[2026-01-01]}
max={~D[2026-12-31]}
locale="en-GB"
errors={if @date_error, do: [@date_error], else: []}
required
/>
<div class="flex flex-wrap gap-2">
<Button.button type="submit">Save date</Button.button>
<Button.button kind={:outline} phx-click="reset-date">Set from server</Button.button>
<Button.button kind={:ghost} type="reset">Reset date</Button.button>
</div>
</.form>
Errors
When bound with field, validation errors render beneath the date picker.
<.form for={@form}>
<DatePicker.date_picker field={@form[:starts_on]} label="Start date" />
</.form>
Add this module
mix dizzy.add date_picker
Component API
DatePicker.date_picker
Attributes
| Name | Type | Default | Values |
|---|---|---|---|
arrow |
:boolean
| false | β |
calendar_label |
:string
| "Choose date" | β |
close_label |
:string
| "Close calendar" | β |
description |
:string
| nil | β |
disabled |
:boolean
| false | β |
errors |
:list
| [] | β |
field |
{:struct, Phoenix.HTML.FormField}
| nil | β |
first_day_of_week |
:integer
| 1 | 0, 1, 2, 3, 4, 5, 6 |
hide |
:boolean
| false | β |
id |
:string
| nil | β |
label |
:string
| nil | β |
locale |
:string
| "en-US" | β |
max |
:any
| nil | β |
min |
:any
| nil | β |
name |
:string
| nil | β |
offset |
:integer
| 8 | β |
placement_strategy |
:atom
| :flip | nil, :flip, :auto_placement |
readonly |
:boolean
| false | β |
required |
:boolean
| false | β |
rest |
:global
| nil | β |
shift |
:boolean
| true | β |
side |
:atom
| :bottom_start | :top, :top_start, :top_end, :bottom, :bottom_start, :bottom_end, :left, :left_start, :left_end, :right, :right_start, :right_end |
strategy |
:atom
| :fixed | :absolute, :fixed |
sublabel |
:string
| nil | β |
value |
:any
| nil | β |
JavaScript hook
DizzyDatePicker
Connects Callyβs calendar to a native date input , emitting input events for Phoenix form changes. Synchronizes server updates, constraints, and resets. Phoenix JS commands control popup visibility; Floating UI positions it. Cally supplies calendar keyboard navigation and date selection. Requires the external cally and @floating-ui/dom npm packages.
mix dizzy.add includes the hook and performs
any required asset setup automatically.