| Install | |
|---|---|
composer require karnoweb/livewire-datepicker |
|
| Latest Version: | v1.0.6 |
| PHP: | ^8.2 |
Datepicker component for Livewire 3 with Alpine.js, supporting Jalali (Persian) and Gregorian calendars. Suitable for Laravel applications that need Persian date selection with optional Gregorian export.
wire:model (single, range, multiple)Y-m-d) in databasemaxSelectionsNo extra npm packages or Vite setup are required in your app — the component loads its script automatically (jalaali-js is bundled inside the package).
jalali_to_gregorian() and gregorian_to_jalali().composer require karnoweb/livewire-datepicker
php artisan vendor:publish --tag=datepicker-config
Edit config/datepicker.php to set default formats, theme, first day of week, and locale strings.
The datepicker script (including jalaali-js) is loaded automatically when you use <x-jalali-datepicker>. No npm install or Vite entry in your app is required.
The component is registered as <x-jalali-datepicker> to avoid collision with Mary-UI's <x-datepicker>.
<x-jalali-datepicker wire:model="birth_date" />
<x-jalali-datepicker
wire:model="birth_date"
label="تاریخ تولد"
placeholder="انتخاب تاریخ"
/>
<x-jalali-datepicker wire:model="event_date" :jalali="false" />
Useful when the database column is a standard date (Y-m-d):
<x-jalali-datepicker
wire:model="birth_date"
jalali
export-calendar="gregorian"
export-format="Y-m-d"
/>
<x-jalali-datepicker wire:model="date_range" :range="true" />
wire:model will receive an object like { "start": "1403/01/01", "end": "1403/01/15" } (or Gregorian if export-calendar="gregorian").
<x-jalali-datepicker wire:model="selected_dates" :multiple="true" />
Optional: limit number of selections:
<x-jalali-datepicker wire:model="selected_dates" :multiple="true" :max-selections="5" />
<x-jalali-datepicker
wire:model="event_date"
min-date="1402/01/01"
max-date="1403/12/29"
/>
Use the same format as input-format (default Y/m/d for Jalali).
Pass an array of date strings in the same format:
<x-jalali-datepicker
wire:model="event_date"
:disabled-dates="['1403/07/01', '1403/07/02']"
/>
Y/m/d, d/m/Y).Y-m-d, Y/m/d).<x-jalali-datepicker
wire:model="event_date"
input-format="Y/m/d"
export-format="Y-m-d"
/>
light / dark / auto (default from config). Override:<x-jalali-datepicker wire:model="event_date" theme="dark" />
Dropdown position (e.g. bottom-start, top-end):
<x-jalali-datepicker wire:model="event_date" position="top-start" />
Show calendar always open (no dropdown):
<x-jalali-datepicker wire:model="event_date" :inline="true" />
<x-jalali-datepicker wire:model="event_date" :required="true" />
<x-jalali-datepicker wire:model="event_date" :disabled="true" />
Set initial value (same format as export):
<x-jalali-datepicker wire:model="event_date" default="1403/06/15" />
| Attribute | Type | Default | Description |
|---|---|---|---|
wire:model |
string | — | Livewire property (required for binding) |
id |
string | auto | Unique ID for the wrapper |
label |
string | null | Label text above the input |
jalali |
bool | true | Use Jalali (true) or Gregorian (false) |
range |
bool | false | Enable date range selection |
multiple |
bool | false | Allow multiple date selection |
required |
bool | false | HTML required |
disabled |
bool | false | Disable input |
inline |
bool | false | Always show calendar (no dropdown) |
min-date |
string | null | Minimum selectable date |
max-date |
string | null | Maximum selectable date |
disabled-dates |
array | [] | List of disabled date strings |
input-format |
string | from config | Display/input format (e.g. Y/m/d) |
export-format |
string | from config | Value format sent to Livewire (e.g. Y-m-d) |
export-calendar |
string | same | same or gregorian (when jalali=true) |
placeholder |
string | locale default | Input placeholder |
default |
string | null | Initial value |
theme |
string | from config | light / dark / auto |
position |
string | bottom-start | Dropdown position |
max-selections |
int | null | Max dates when multiple=true |
After publishing config (config/datepicker.php):
jalali or gregorianY/m/d)Y-m-d)auto, light, or darkThe package provides two helpers for server-side conversion:
use function Karnoweb\LivewireDatepicker\gregorian_to_jalali;
use function Karnoweb\LivewireDatepicker\jalali_to_gregorian;
// Gregorian to Jalali: year, month, day
$j = gregorian_to_jalali(2024, 3, 20);
// ['year' => 1403, 'month' => 1, 'day' => 1]
// Jalali to Gregorian
$g = jalali_to_gregorian(1403, 1, 1);
// ['year' => 2024, 'month' => 3, 'day' => 20]
php artisan vendor:publish --tag=datepicker-configphp artisan vendor:publish --tag=datepicker-views → customize Blade under resources/views/vendor/datepickerphp artisan vendor:publish --tag=datepicker-assets → copies raw JS sources to public/vendor/datepicker (only if you want to build them in your app; normally the bundled script is served by the package)karnoweb/livewire-datepickerKarnoweb\LivewireDatepicker<x-jalali-datepicker /> (prefix jalali to avoid Mary-UI collision)So clients can get the latest changes via Composer, each release must be tagged. Steps:
composer.json (e.g. 1.0.2 → 1.0.3).resources/js/): run npm install && npm run build and commit dist/datepicker.js.git add .
git commit -m "v1.0.3: your message"
git tag v1.0.3
git push && git push --tags
Clients using "karnoweb/livewire-datepicker": "^1.0" can then run composer update karnoweb/livewire-datepicker to get the new release.
MIT.