Loki_Flatpickr

This module is available free of charge as part of the Loki Checkout Open Source plan. Please note that support for this module is not to be taken for granted though. If you want our dedicated help, opt for a paid plan instead.
Component Library
module.plan-free
Professional
Standard
Trial
PHP 8.2 - 8.5
Magento 2.4.6 - 2.4.9
CSP Yes
Unit Tests 7
Integration Tests 14
Functional Tests 8
PHPStan 5
Magento PHPCS 6
License OSL-3.0
Latest Release 1.0.9

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.script.directive.flatpickr. If you want to change the options for Flatpickr, you can use the block argument options for this:

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

Instead of a global configuration, options can also be set per field:

<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="array">
                <item name="altFormat" xsi:type="string">d-m-Y</item>
            </item>
        </argument>
    </arguments>
</block>

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).

Current status

Magento 2 Unit Tests success
Magento 2 Static Tests success
Magento 2 DI compilation success
Playwright test success
Magento 2 Integration Tests success
Magento 2 Unit Tests success
Magento 2 DI compilation success
Playwright test success
Magento 2 Integration Tests success
Magento 2 Static Tests success

Support

For getting support, create an Issue under the following project URL:

https://github.com/LokiExtensions/Loki_Flatpickr

Module Dependencies

The following dependencies are declared in the module its `etc/module.xml` file:

Loki_Base Loki_Components Loki_CssUtils Magento_Backend Magento_Config Magento_Csp Magento_Customer Magento_Directory Magento_Eav Magento_Quote Magento_Store Magento_Theme Yireo_CspUtilities
Composer details
Magento module name
Loki_Flatpickr
Composer name
loki/magento2-flatpickr
Composer version
1.0.9
Default branch
master
Requirements
ext-json: *
loki/magento2-components: ^2.2
magento/framework: ^103.0
magento/module-store: ^101.0
php: >=8.2 <8.6
Releases
1.0.9 12 November 2026
1.0.8 12 November 2026
1.0.7 12 November 2026
1.0.6 12 November 2026
1.0.5 12 November 2026
1.0.4 12 November 2026
1.0.3 12 November 2026
1.0.2 12 November 2026
1.0.1 12 November 2026
1.0.0 12 November 2026
Changelog

[1.0.9] - 29 October 2026

Fixed

  • Fix name of Flatpickr directive block in README
  • Define window.flatpickr when RequireJS is present
  • Safely output Flatpickr options containing quotes

[1.0.8] - 19 May 2026

Fixed

  • Do not preload Flatpickr CSS

[1.0.7] - 08 April 2026

Fixed

  • Properly set first day of week
  • Allow setting options per field

[1.0.6] - 23 January 2026

Fixed

  • Increase PHPCS_LEVEL to 6
  • Add new GitHub Action workflows

[1.0.5] - 12 December 2025

Fixed

  • Do not defer CSS
  • Update composer keywords
  • Update composer keywords
  • Update composer keywords

[1.0.4] - 23 September 2025

Fixed

  • Rename loki.script from container to block to allow caching
  • Rename loki script containers

[1.0.3] - 04 September 2025

Fixed

  • Loading Flatpickr JS async does not work
  • Remove redundant field_type definition from README

[1.0.2] - 03 September 2025

Fixed

  • array_merge_recursive does not work, use array_merge instead
  • Add examples to README

[1.0.1] - 02 September 2025

Fixed

  • Optimize loading of remote resources
  • Allow configuring options from XML layout
  • Add additional handle loki_flatpickr for usage outside of Loki Components

[1.0.0] - 31 August 2025

Added

  • Initial release

Last modified: June 1, 2026