loki/magento2-flatpickr

Magento 2 module to add an Alpine.js directive x-flatpickr

Fund package maintenance!
yireo
www.paypal.me/yireo

Installs: 9

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Type:magento2-module

1.0.3 2025-09-04 08:25 UTC

This package is auto-updated.

Last update: 2025-09-05 10:13:24 UTC


README

This Magento 2 module adds an Alpine.js x-flatpickr directive to transform a simple input field into a Flatpickr date picker.

Installation

composer require loki/magento2-flatpickr
bin/magento module:enable Loki_Flatpickr

Usage

To add Flatpickr to a custom HTML input, just add the x-flatpickr directive to your HTML element:

<input type="date" x-flatpickr/>

If you want to add Flatpickr to a Loki Field Component, add the x-flatpickr directive via the XML layout:

<block name="example" template="Loki_FieldComponents::form/field.phtml">
    <arguments>
        <argument name="input_type" xsi:type="string">date</argument>
        <argument name="field_attributes" xsi:type="array">
            <item name="x-flatpickr" xsi:type="boolean">true</item>
        </argument>
    </arguments>
</block>

Customization

The Flatpickr directive is inserted via a block loki.directives.flatpickr. If you want to change the options for Flatpickr, you can use the block argument options for this:

<referenceBlock name="loki.directives.flatpickr">
    <arguments>
        <argument name="options" xsi:type="array">
            <item name="altFormat" xsi:type="string">d-m-Y</item>
        </argument>
    </arguments>
</referenceBlock>

For all options, see https://flatpickr.js.org/options/

Note that changing the dateFormat will also change the value sent to Magento. It is probably best to keep this at its default (Y-m-d).