Skip to content

Commit 46d2752

Browse files
authored
FixDateRangeFilter (rappasoft#1872)
1 parent 74c35e2 commit 46d2752

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

docs/filter-types/filters-daterange.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function filters(): array
4646
A full list of options is below, please see the Flatpickr documentation for reference as to purpose:
4747
| Config Option | Type | Default | Description |
4848
| ------------- | ------------- | ------------- | ------------- |
49+
| allowInvalidPreload | Boolean | true | Allows the preloading of an invalid date. When disabled, the field will be cleared if the provided date is invalid |
4950
| allowInput | Boolean | false | Allows the user to enter a date directly into the input field. By default, direct entry is disabled. |
5051
| altFormat | String | "F j, Y" | Exactly the same as date format, but for the altInput field |
5152
| altInput | Boolean | false | Show the user a readable date (as per altFormat), but return something totally different to the server. |
@@ -153,7 +154,7 @@ If using the CDN approach, ensure the following config matches:
153154
Then include the following in your layout:
154155
```html
155156
// Flatpickr Core Script
156-
<script src="https://npmcdn.com/flatpickr" async></script>
157+
<script src="https://npmcdn.com/flatpickr" defer></script>
157158

158159
// Flatpickr Core CSS
159160
<link rel="stylesheet" href="https://npmcdn.com/flatpickr/dist/flatpickr.min.css">
@@ -193,5 +194,5 @@ You can also add locales using the Flatpickr CDN, ensuring that these are loaded
193194

194195
For example to add German (de), ensure that the following is in the "head" section of your layout, ideally before your app.js
195196
```html
196-
<script src="https://npmcdn.com/flatpickr/dist/l10n/de.js" async></script>
197+
<script src="https://npmcdn.com/flatpickr/dist/l10n/de.js" defer></script>
197198
```

resources/js/laravel-livewire-tables.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ document.addEventListener('alpine:init', () => {
311311
altFormat: filterConfig['altFormat'] ?? "F j, Y",
312312
altInput: filterConfig['altInput'] ?? false,
313313
allowInput: filterConfig['allowInput'] ?? false,
314-
allowInvalidPreload: true,
314+
allowInvalidPreload: filterConfig['allowInvalidPreload'] ?? true,
315315
ariaDateFormat: filterConfig['ariaDateFormat'] ?? "F j, Y",
316316
clickOpens: true,
317317
dateFormat: filterConfig['dateFormat'] ?? "Y-m-d",
@@ -333,15 +333,16 @@ document.addEventListener('alpine:init', () => {
333333
},
334334
onChange: function (selectedDates, dateStr, instance) {
335335
if (selectedDates.length > 1) {
336-
var startDate = dateStr.split(' ')[0];
337-
var endDate = dateStr.split(' ')[2];
336+
var dates = dateStr.split(' ');
337+
338338
var wireDateArray = {};
339339
window.childElementOpen = false;
340340
window.filterPopoverOpen = false;
341-
wireDateArray = { 'minDate': startDate, 'maxDate': endDate };
341+
wireDateArray = { 'minDate': dates[0], 'maxDate': (typeof dates[2] === "undefined") ? dates[0] : dates[2] };
342342
wire.set('filterComponents.' + filterKey, wireDateArray);
343343
}
344-
}
344+
345+
},
345346
}),
346347
setupWire() {
347348
if (this.wireValues !== undefined) {

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.

resources/js/partials/filter-date-range.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function fpf() {
88
altFormat: filterConfig['altFormat'] ?? "F j, Y",
99
altInput: filterConfig['altInput'] ?? false,
1010
allowInput: filterConfig['allowInput'] ?? false,
11-
allowInvalidPreload: true,
11+
allowInvalidPreload: filterConfig['allowInvalidPreload'] ?? true,
1212
ariaDateFormat: filterConfig['ariaDateFormat'] ?? "F j, Y",
1313
clickOpens: true,
1414
dateFormat: filterConfig['dateFormat'] ?? "Y-m-d",
@@ -30,15 +30,16 @@ function fpf() {
3030
},
3131
onChange: function (selectedDates, dateStr, instance) {
3232
if (selectedDates.length > 1) {
33-
var startDate = dateStr.split(' ')[0];
34-
var endDate = dateStr.split(' ')[2];
33+
var dates = dateStr.split(' ');
34+
3535
var wireDateArray = {};
3636
window.childElementOpen = false;
3737
window.filterPopoverOpen = false;
38-
wireDateArray = { 'minDate': startDate, 'maxDate': endDate };
38+
wireDateArray = { 'minDate': dates[0], 'maxDate': (typeof dates[2] === "undefined") ? dates[0] : dates[2] };
3939
wire.set('filterComponents.' + filterKey, wireDateArray);
4040
}
41-
}
41+
42+
},
4243
}),
4344
setupWire() {
4445
if (this.wireValues !== undefined) {

resources/js/partials/filter-date-range.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)