Date Edit
RzDateEdit is a date input with a calendar popup, bound to a nullable DateTime model property through For. It must be placed inside an EditForm. The calendar is provided by Flatpickr, configured from the server with FlatpickrOptions; the rzDateEdit Alpine component loads Flatpickr and creates the picker. There is no Blazor interactivity: the input carries the same name as Blazor's own inputs (for example Model.StartDate), so the date is submitted with the form and binds to the model, and validation attributes from data annotations such as [Required] are added.
Under the Hood
The component renders x-data="rzDateEdit" with the serialized options in data-config. On initialization it loads the FlatpickrCore asset (see ComponentAssetKeys) and calls flatpickr(input, options) with a copy of those options. When the element is removed, for example by an htmx swap, the Alpine destroy() hook destroys the Flatpickr instance, which removes its calendar element and document listeners.
Basic Usage
Bind the component to a DateTime? property with For. The current value is shown in the input and preselected in the calendar.
<EditForm Model="_model">
<Field>
<FieldLabel For="@(() => _model.StartDate)">Start date</FieldLabel>
<RzDateEdit For="@(() => _model.StartDate)" Placeholder="Select a date" />
</Field>
</EditForm>
@code {
private readonly EventModel _model = new() { StartDate = new DateTime(2026, 11, 15) };
private sealed class EventModel
{
public DateTime? StartDate { get; set; }
}
}Flatpickr Options
Pass a FlatpickrOptions object to Options to configure the calendar. This example shows dates as day/month/year with DateFormat (Flatpickr tokens; the server renders the value in the same format), limits the selectable range with MinDate and MaxDate, and adds a calendar icon with PrependIcon. Dates outside the range are disabled in the calendar.
Submitted format
The form submits the value as it is displayed, in DateFormat. The default Y-m-d posts 2026-11-20, which binds to DateTime. With another format (here 01/12/2026), make sure the server parses it.
<EditForm Model="_model">
<RzDateEdit For="@(() => _model.EndDate)"
Options="@(new FlatpickrOptions { Locale = "en", DateFormat = "d/m/Y", MinDate = new DateTime(2026, 11, 1), MaxDate = new DateTime(2026, 12, 31) })"
PrependIcon="MdiIcon.Calendar"
Placeholder="November or December" />
</EditForm>Loading with htmx
A date field can be loaded or replaced by an htmx request. Each time the button is used, the previous field is removed and its Flatpickr instance destroyed, so calendars do not accumulate in the page.
<RzButton hx-get="/demo/date-edit-sample"
hx-target="#date-edit-htmx-target"
hx-swap="innerHTML">
Load date field
</RzButton>
<div id="date-edit-htmx-target"></div>@page "/demo/date-edit-sample"
@layout EmptyLayout
<EditForm Model="_model">
<RzDateEdit For="@(() => _model.Deadline)"
Options="@(new FlatpickrOptions { Locale = "en", MinDate = new DateTime(2026, 11, 1), MaxDate = new DateTime(2026, 12, 31) })"
Placeholder="Select a deadline" />
</EditForm>Accessibility
The component renders a role="group" container labelled "Date picker" around a text input labelled "Select date". Keyboard support comes from Flatpickr. By default Flatpickr makes the input read-only; set AllowInput = true in FlatpickrOptions to let users type a date.
| Key | Effect |
|---|---|
| Click or focus the input | Opens the calendar; focus stays on the input. |
| Down Arrow (on the input) | Moves focus into the calendar, onto the selected day. |
| Left / Right Arrow (on a day) | Previous / next day. |
| Up / Down Arrow (on a day) | Same day of the previous / next week. |
| Enter (on a day) | Selects the day, closes the calendar and returns focus to the input. |
| Escape | Closes the calendar without changing the value and returns focus to the input. |
Known limitations
The input has aria-label="Select date", which screen readers use instead of the text of a FieldLabel (the label still points at the input and focuses it on click). Tab from a calendar day moves focus out of the calendar (it is appended to the end of the page) while it stays open. The labels are fixed English strings, and the calendar has not been tested with screen readers.
Component Parameters
| Property | Description | Type | Default |
|---|---|---|---|
For Required | The model property the date is bound to. The component must be inside an EditForm. | Expression<Func<DateTime?>> | null |
Options | Flatpickr configuration (for example DateFormat, MinDate, MaxDate, EnableTime, AllowInput). Dates are sent as ISO strings and converted to local dates before Flatpickr reads them, so they work with any DateFormat. DefaultDate is filled from the bound value when not set; the Options instance itself is not modified. | FlatpickrOptions | new() { Locale = "en" } |
Placeholder | Placeholder text for the input. | string | "" |
PrependText | Text shown at the start of the input. Takes precedence over PrependIcon. | string? | null |
PrependIcon | Icon shown at the start of the input. | SvgIcon? | null |
ComponentAssetKeys | Keys in RizzyUIConfig.AssetUrls for the scripts to load. With an empty array, Flatpickr must already be loaded by the page (window.flatpickr). | string[] | ["FlatpickrCore"] |
Alpine API
The rzDateEdit Alpine component has no public methods for application code and raises no events. Its lifecycle hooks are listed for reference.
| Method | Parameters | Description |
|---|---|---|
init() | — | Reads data-config, loads the assets and creates the Flatpickr instance with a copy of the options. |
destroy() | — | Called by Alpine when the element is removed. Destroys the Flatpickr instance, or prevents it from being created if the assets are still loading. |