Skip to content

Commit b5d299d

Browse files
authored
* Add more FlatpickrJS options
1 parent e74d834 commit b5d299d

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

docs/filter-types/filters-daterange.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,30 @@ public function filters(): array
4343
}
4444
```
4545

46+
A full list of options is below, please see the Flatpickr documentation for reference as to purpose:
47+
| Config Option | Type | Default | Description |
48+
| ------------- | ------------- | ------------- | ------------- |
49+
| allowInput | Boolean | false | Allows the user to enter a date directly into the input field. By default, direct entry is disabled. |
50+
| altFormat | String | "F j, Y" | Exactly the same as date format, but for the altInput field |
51+
| altInput | Boolean | false | Show the user a readable date (as per altFormat), but return something totally different to the server. |
52+
| ariaDateFormat | String | "F j, Y" | Defines how the date will be formatted in the aria-label for calendar days, using the same tokens as dateFormat. If you change this, you should choose a value that will make sense if a screen reader reads it out loud. |
53+
| dateFormat | String | 'Y-m-d' | A string of characters which are used to define how the date will be displayed in the input box |
54+
| defaultDate | String | null | Sets the initial selected date |
55+
| defaultHour | Number | 12 | Initial value of the hour element. |
56+
| defaultMinute | Number | 0 | Initial value of the minute element. |
57+
| earliestDate | String/Date | null | The minimum date that a user can start picking from (inclusive) |
58+
| enableTime | Boolean | false | Enables time picker |
59+
| enableSeconds | Boolean | false | Enables seconds in the time picker. |
60+
| hourIncrement | Integer | 1 | Adjusts the step for the hour input (incl. scrolling) |
61+
| latestDate | String/Date | null | The maximum date that a user can pick to (inclusive) |
62+
| locale | String | en | The locale used (see below) |
63+
| minuteIncrement | Integer | 5 | Adjusts the step for the minute input (incl. scrolling) |
64+
| placeholder | String | null | Set a placeholder value for the input field |
65+
| shorthandCurrentMonth | Boolean | false | Show the month using the shorthand version (ie, Sep instead of September). |
66+
| time_24hr | Boolean | false | Displays time picker in 24 hour mode without AM/PM selection when enabled. |
67+
| weekNumbers | Boolean | false | Enables display of week numbers in calendar. |
68+
69+
4670
## Configuration
4771
By default, this filter will inject the Flatpickr JS Library and CSS. However, you can customise this behaviour using the configuration file.
4872

resources/js/laravel-livewire-tables.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,26 @@ document.addEventListener('alpine:init', () => {
121121
wireValues: wire.entangle('filterComponents.' + filterKey),
122122
flatpickrInstance: flatpickr(refLocation, {
123123
mode: 'range',
124-
clickOpens: true,
124+
altFormat: filterConfig['altFormat'] ?? "F j, Y",
125+
altInput: filterConfig['altInput'] ?? false,
126+
allowInput: filterConfig['allowInput'] ?? false,
125127
allowInvalidPreload: true,
126-
defaultDate: [],
127-
ariaDateFormat: filterConfig['ariaDateFormat'],
128-
allowInput: filterConfig['allowInput'],
129-
altFormat: filterConfig['altFormat'],
130-
altInput: filterConfig['altInput'],
131-
dateFormat: filterConfig['dateFormat'],
132-
locale: 'en',
133-
minDate: filterConfig['earliestDate'],
134-
maxDate: filterConfig['latestDate'],
128+
ariaDateFormat: filterConfig['ariaDateFormat'] ?? "F j, Y",
129+
clickOpens: true,
130+
dateFormat: filterConfig['dateFormat'] ?? "Y-m-d",
131+
defaultDate: filterConfig['defaultDate'] ?? null,
132+
defaultHour: filterConfig['defaultHour'] ?? 12,
133+
defaultMinute: filterConfig['defaultMinute'] ?? 0,
134+
enableTime: filterConfig['enableTime'] ?? false,
135+
enableSeconds: filterConfig['enableSeconds'] ?? false,
136+
hourIncrement: filterConfig['hourIncrement'] ?? 1,
137+
locale: filterConfig['locale'] ?? 'en',
138+
minDate: filterConfig['earliestDate'] ?? null,
139+
maxDate: filterConfig['latestDate'] ?? null,
140+
minuteIncrement: filterConfig['minuteIncrement'] ?? 5,
141+
shorthandCurrentMonth: filterConfig['shorthandCurrentMonth'] ?? false,
142+
time_24hr: filterConfig['time_24hr'] ?? false,
143+
weekNumbers: filterConfig['weekNumbers'] ?? false,
135144
onOpen: function () {
136145
window.childElementOpen = true;
137146
},

resources/js/laravel-livewire-tables.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)