File tree Expand file tree Collapse file tree
view/frontend/templates/script Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,6 +39,20 @@ The Flatpickr directive is inserted via a block `loki.directives.flatpickr`. If
3939</referenceBlock >
4040```
4141
42+ Instead of a global configuration, options can also be set per field:
43+ ``` xml
44+ <block name =" example" template =" Loki_FieldComponents::form/field.phtml" >
45+ <arguments >
46+ <argument name =" input_type" xsi : type =" string" >date</argument >
47+ <argument name =" field_attributes" xsi : type =" array" >
48+ <item name =" x-flatpickr" xsi : type =" array" >
49+ <item name =" altFormat" xsi : type =" string" >d-m-Y</item >
50+ </item >
51+ </argument >
52+ </arguments >
53+ </block >
54+ ```
55+
4256For all options, see [ https://flatpickr.js.org/options/ ] ( https://flatpickr.js.org/options/ )
4357
4458Note 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 ` ).
Original file line number Diff line number Diff line change 11<?php
22declare (strict_types=1 );
33
4- /** @version 1.0.6 */
5-
64use Loki \Components \Factory \ViewModelFactory ;
75use Loki \Flatpickr \ViewModel \Options ;
86use Magento \Framework \View \Element \Template ;
97
8+ /** @version 1.0.6 */
109/** @var Template $block */
1110/** @var ViewModelFactory $viewModelFactory */
1211/** @var Options $options */
1312$ options = $ viewModelFactory ->create (Options::class);
1413?>
1514<script>
1615 document.addEventListener('alpine:init', () => {
17- Alpine.directive('flatpickr', (el, {}) => {
18- flatpickr(el, JSON.parse('<?= /* @noEscape */ $ options ->toJson ($ block ) ?> '));
16+ Alpine.directive('flatpickr', (el, {expression}) => {
17+ const options = Object.assign(
18+ JSON.parse('<?= /* @noEscape */ $ options ->toJson ($ block ) ?> '),
19+ expression.length > 0 ? JSON.parse(expression) : {},
20+ );
21+
22+ flatpickr(el, options);
1923 });
2024 });
2125</script>
You can’t perform that action at this time.
0 commit comments