Date range
Lets users pick a start and an end day in one field, from a calendar.
zb:date-range zubazar/ui-pro
Needs a JavaScript library registration: see Setup.
This component is in Zubazar UI Pro; Zubazar UI Pro brings Zubazar UI with it. Installing Zubazar UI Pro →
Classic form
start-name and end-name name two hidden fields; the form sends the range in them as Y-m-d.
<div x-data="{ range: null }" x-on:date-range-picked="range = $event.detail" class="space-y-2">
<zb:date-range label="Report period" start-name="from" end-name="until" hint="Orders between these days are listed." />
<p class="text-sm text-dim" x-text="range ? 'Will send: from=' + range.start + ', until=' + range.end : 'Pick a start and an end day.'"></p>
</div>
| Prop | Values |
|---|---|
start-name, end-name | The hidden fields' names |
start, end | The range chosen at first (Y-m-d) |
With Livewire
start-property and end-property are the component properties the selection is written to; give the initial values from the same properties.
{{-- In the Livewire component: public ?string $from = null; public ?string $until = null; --}}
<zb:date-range
label="Order date"
start-property="from"
end-property="until"
:start="$from"
:end="$until"
/>
| Prop | Values |
|---|---|
start-property, end-property | The properties written to |
date-range-picked | The event when the range is complete: { start, end } |
Closed days and format
min-date="today" blocks past days and :disabled-ranges blocks given days or ranges; format changes the format shown in the field.
<zb:date-range
label="Campaign period"
start-name="campaign_start"
end-name="campaign_end"
min-date="today"
:disabled-ranges="[['from' => '2026-12-24', 'to' => '2026-12-26'], '2026-12-31']"
format="j M Y"
/>
| Prop | Values |
|---|---|
min-date | 'today' | Y-m-d |
disabled-ranges | Dates or from/to ranges |
format | A flatpickr format |
Props
The values the component takes. What are props and slots?
| Prop | Type | Default | Description |
|---|---|---|---|
label | — | null | The label above the field |
hint | — | null | The help text below; an error replaces it |
placeholder | — | Choose a date range | The text in the empty field |
start, end | — | null | The range chosen at first (Y-m-d) |
startProperty, endProperty | — | null | Livewire: the properties the range is written to |
startName, endName | — | null | A classic form: the hidden fields' names; old() values come back after a failed validation |
minDate | — | null | The first day that can be chosen: 'today' or Y-m-d |
disabledRanges | — | [] | Days that cannot be chosen: dates or ['from' => …, 'to' => …] |
format | — | null | How the range reads in the field (flatpickr); by default d.m.Y or m/d/Y by the page's language |
input-class | — | null | Classes of the field itself; class places the whole field |
Slots: class, style, x-show and wire:key go on the element around the whole field (with the label and the message); other attributes such as required, disabled, aria-* and events go on the field. x-on:date-range-picked can also be written on zb:date-range itself.
Installation
Install flatpickr and register it in resources/js/app.js; the calendar opens in the page's language.
// npm install flatpickr
// resources/js/app.js
document.addEventListener('livewire:init', () => {
const { lazyLibrary, registerDateRangePicker } = window.ZubazarUI.pro;
registerDateRangePicker(window.Alpine, lazyLibrary(async () => {
const turkish = document.documentElement.lang.startsWith('tr');
const [{ default: flatpickr }, locale] = await Promise.all([
import('flatpickr'),
turkish ? import('flatpickr/dist/l10n/tr.js') : Promise.resolve(null),
import('flatpickr/dist/flatpickr.min.css'),
]);
if (locale) flatpickr.localize(locale.Turkish);
return flatpickr;
}));
});
Developer notes
- The calendar sits in
wire:ignore; a range the server writes to the properties (e.g. a reset after saving) reaches it too, and the label, hint and error refresh with Livewire updates. - A validation error on either property shows below the field; your
aria-describedbyvalue is merged with the message's id.
Events
| Event | detail | Description |
|---|---|---|
date-range-picked | { start, end } | Sent from the field (the original input, which stays hidden in the page) when both days are picked; it bubbles. Dates are Y-m-d strings. Also sent when the range is set from code or by the server; a cleared range gives empty strings. |