From 6ed8529e1ba22499db2f51ffe969fe34fa973ae2 Mon Sep 17 00:00:00 2001 From: l_samenv Date: Thu, 29 Aug 2024 14:35:27 +0200 Subject: [PATCH] Date input for jump is the last set --- client/components/dates_popup/dates_popup.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/client/components/dates_popup/dates_popup.js b/client/components/dates_popup/dates_popup.js index 00ac9d8..bfd7c3e 100644 --- a/client/components/dates_popup/dates_popup.js +++ b/client/components/dates_popup/dates_popup.js @@ -54,24 +54,31 @@ class DatesPopup extends HTMLElement{ } show(){ - this.setInitialDates(); + this.setMaxInputDate(); this.style.visibility = "visible"; } - setInitialDates(){ + getCorrectedCurrentDate(){ let currentDate = new Date(); let correctedCurrentDate = new Date(Date.UTC(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate())); + return correctedCurrentDate; + } + + setInitialInputDate(){ let dateInput = this.getElementsByClassName("input-date")[0]; - let dateDayBefore = new Date(correctedCurrentDate - DatesPopup.DAY); + let dateDayBefore = new Date(this.getCorrectedCurrentDate() - DatesPopup.DAY); dateInput.valueAsDate = dateDayBefore; + } - this.getElementsByClassName("input-date")[0].max = correctedCurrentDate.toISOString().split("T")[0]; // sets the max to today (set only at app start) - + setMaxInputDate(){ + let dateInput = this.getElementsByClassName("input-date")[0]; + dateInput.max = this.getCorrectedCurrentDate().toISOString().split("T")[0]; // sets the max to today (set each time the pop up is displayed) } connectedCallback(){ this.render(); this.hide(); + this.setInitialInputDate(); this.getElementsByTagName("img")[0].onclick = () => {this.hide();}; this.getElementsByClassName("go-to-now-button")[0].onclick = () => {this.doGoToNowCallback();}; this.getElementsByClassName("jump-button")[0].onclick = () => {this.doJumpCallback();};