Skip to content

Commit 963718a

Browse files
authored
Merge pull request #80 from imbus/bugfix-predefined-filter-date-is-broken-again
Bugfix predefined filter date is broken again
2 parents 04cb0cc + 64c50c9 commit 963718a

File tree

7 files changed

+108
-110
lines changed

7 files changed

+108
-110
lines changed

public/js/dist/filterFormManager.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ export default class FilterFormManager {
6161
clearAll() {
6262
//this.collectFilterData();
6363
this.inputs.forEach(field => {
64-
queueMicrotask(() => {
6564
field.clear();
66-
})
6765
});
6866
}
6967

public/js/dist/filterFormManager.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.

public/js/dist/filterInputs.js

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -257,39 +257,62 @@ class AssignedEntityFilterInput extends SelectFilterInput {
257257
}
258258

259259
class DateFilterInput extends FilterInput {
260-
261260
constructor(el, apiService) {
262261
super(el, apiService);
263262

264-
this.container = this.element.closest('.input-daterange');
263+
// assign as class properties
264+
this.startDatepickerInput = document.getElementById(el.id + "_start");
265+
this.endDatepickerInput = document.getElementById(el.id + "_end");
266+
267+
if (this.startDatepickerInput) {
268+
this.startDatepicker = $(this.startDatepickerInput).datepicker({
269+
todayBtn: "linked",
270+
clearBtn: true,
271+
disableTouchKeyboard: true,
272+
forceParse: false,
273+
keepEmptyValues: true,
274+
daysOfWeekHighlighted: "0,6",
275+
todayHighlight: true,
276+
format: "yyyy-mm-dd",
277+
});
278+
}
265279

266-
let datepicker = null;
267-
if (this.container) {
268-
datepicker = $(this.container).datepicker({
280+
if (this.endDatepickerInput) {
281+
this.endDatepicker = $(this.endDatepickerInput).datepicker({
269282
todayBtn: "linked",
270283
clearBtn: true,
271284
disableTouchKeyboard: true,
272285
forceParse: false,
273286
keepEmptyValues: true,
274287
daysOfWeekHighlighted: "0,6",
275-
todayHighlight: true
288+
todayHighlight: true,
289+
format: "yyyy-mm-dd",
276290
});
277291
}
278292

279-
datepicker.on('changeDate', (event) => {
280-
if (event.target.id.endsWith("_start")) {
293+
// event listeners (check element exists)
294+
if (this.startDatepickerInput) {
295+
$(this.startDatepickerInput).on('changeDate', (event) => {
281296
this.startDate = new Intl.DateTimeFormat('en-CA').format(event.date);
282-
} else {
297+
});
298+
299+
$(this.startDatepickerInput).on('clearDate', (_) => {
300+
this.startDate = undefined;
301+
});
302+
}
303+
304+
if (this.endDatepickerInput) {
305+
$(this.endDatepickerInput).on('changeDate', (event) => {
283306
this.endDate = new Intl.DateTimeFormat('en-CA').format(event.date);
284-
}
285-
});
307+
});
286308

287-
datepicker.on('clearDate', (_) => {
288-
this.startDate = undefined;
289-
this.endDate = undefined;
290-
});
309+
$(this.endDatepickerInput).on('clearDate', (_) => {
310+
this.endDate = undefined;
311+
});
312+
}
291313
}
292314

315+
293316
getValue() {
294317
const result = {};
295318

@@ -302,47 +325,21 @@ class DateFilterInput extends FilterInput {
302325
return result;
303326
}
304327

305-
/*setValue() {
306-
$(this.container).datepicker('setStartDate', '2020-01-01');
307-
//console.error("Currently not implemented");
308-
//throw new Error("Currently not implemented");
309-
//return this.hasValue() ? this.element.value : null;
310-
}*/
311-
312328
setValue(newValue, logic, operator) {
313-
console.log("setdate");
329+
314330
return new Promise((resolve, reject) => {
315331
try {
316-
//console.log(newValue);
317-
318-
const $container = $(this.container);
319-
const $startInput = $container.find('input:first');
320-
const $endInput = $container.find('input:last');
321-
console.log($startInput);
322-
console.log($endInput);
323332

324333
if (newValue.startDate != undefined) {
325-
// Set the value directly and update datepicker
326-
$startInput.val = newValue.startDate;
327-
const d = document.getElementById($startInput[0].id);
328-
console.log(d);
329-
d.value = newValue.startDate;
330-
$startInput.datepicker('update');
334+
const startDateObject = new Date(newValue.startDate);
335+
this.startDatepicker.datepicker('setDate', startDateObject);
331336
}
332337

333338
if (newValue.endDate != undefined) {
334-
// Set the value directly and update datepicker
335-
$endInput.val = newValue.endDate;
336-
const d = document.getElementById($endInput[0].id);
337-
console.log(d);
338-
d.value = newValue.endDate;
339-
$endInput.datepicker('update');
339+
const endDateObject = new Date(newValue.endDate);
340+
this.endDatepicker.datepicker('setDate', endDateObject);
340341
}
341342

342-
// Trigger change event to update any listeners
343-
$startInput.trigger('changeDate');
344-
$endInput.trigger('changeDate');
345-
346343
this.setSearchOperator(logic, operator);
347344
resolve(newValue);
348345
}
@@ -355,10 +352,14 @@ class DateFilterInput extends FilterInput {
355352

356353
clear() {
357354
const r = this.getValue();
358-
if (r.startDate !== undefined || r.endDate !== undefined) {
359-
// I don't know why this is needed but without it won't reset properly
360-
$(this.container).datepicker('setDates', ['2000-01-01', '2000-01-02']);
361-
$(this.container).datepicker('clearDates');
355+
console.log("r", r);
356+
if (r.startDate !== undefined || jQuery.isEmptyObject(r) === false) {
357+
this.startDatepicker.datepicker('clearDates');
358+
this.startDate = undefined;
359+
}
360+
if (r.endDate !== undefined || jQuery.isEmptyObject(r) === false) {
361+
this.endDatepicker.datepicker('clearDates');
362+
this.endDate = undefined;
362363
}
363364

364365
super.clear();

public/js/dist/filterInputs.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)