This Magento 2 module adds an Alpine.js x-flatpickr
directive to transform a simple input field into a Flatpickr date picker.
composer require loki/magento2-flatpickr
bin/magento module:enable Loki_Flatpickr
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>
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
).
For getting support, create an Issue under the following project URL:
https://github.com/LokiExtensions/Loki_Flatpickr
The following dependencies are declared in the module its `etc/module.xml` file:
Loki_Base
Loki_Components
Loki_CssUtils
Magento_Backend
Magento_Config
Magento_Customer
Magento_Store
Yireo_CspUtilities
Loki_Flatpickr
loki/magento2-flatpickr
ext-json: *
loki/magento2-components: ^2.0
magento/framework: ^103.0
dev-master#4b2e7022e473b3b902ed90a45b80a8194a101aeb | 20 October 2025 |
1.0.4 | 20 October 2025 |
1.0.3 | 20 October 2025 |
1.0.2 | 20 October 2025 |
1.0.1 | 20 October 2025 |
1.0.0 | 20 October 2025 |
field_type
definition from READMEarray_merge_recursive
does not work, use array_merge
insteadloki_flatpickr
for usage outside of Loki Components