@@ -257,39 +257,62 @@ class AssignedEntityFilterInput extends SelectFilterInput {
257257}
258258
259259class 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
@@ -310,40 +333,24 @@ class DateFilterInput extends FilterInput {
310333 }*/
311334
312335 setValue ( newValue , logic , operator ) {
313- console . log ( "setdate" ) ;
336+
314337 return new Promise ( ( resolve , reject ) => {
315338 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 ) ;
323339
324340 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' ) ;
341+ const startDateObject = new Date ( newValue . startDate ) ;
342+ console . log ( "start" , newValue . startDate , startDateObject ) ;
343+ this . startDatepicker . datepicker ( 'setDate' , startDateObject ) ;
331344 }
332345
333346 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' ) ;
347+ const endDateObject = new Date ( newValue . endDate ) ;
348+ console . log ( "end" , newValue . endDate , endDateObject ) ;
349+ this . endDatepicker . datepicker ( 'setDate' , endDateObject ) ;
340350 }
341351
342- // Trigger change event to update any listeners
343- $startInput . trigger ( 'changeDate' ) ;
344- $endInput . trigger ( 'changeDate' ) ;
345-
346352 this . setSearchOperator ( logic , operator ) ;
353+ console . log ( "this.getvalues" , this . getValue ( ) ) ;
347354 resolve ( newValue ) ;
348355 }
349356 catch ( e ) {
@@ -354,12 +361,16 @@ class DateFilterInput extends FilterInput {
354361 }
355362
356363 clear ( ) {
357- const r = this . getValue ( ) ;
364+ /* const r = this.getValue();
358365 if (r.startDate !== undefined || r.endDate !== undefined) {
359366 // I don't know why this is needed but without it won't reset properly
360367 $(this.container).datepicker('setDates', ['2000-01-01', '2000-01-02']);
361368 $(this.container).datepicker('clearDates');
362- }
369+ }*/
370+ //this.startDatepicker.datepicker('clearDates');
371+ //this.endDatepicker.datepicker('clearDates');
372+ this . startDate = undefined ;
373+ this . endDate = undefined ;
363374
364375 super . clear ( ) ;
365376 }
0 commit comments