From 83b98ac66c24c97959c195c159113508d3483253 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 2 Nov 2020 16:29:35 +0100 Subject: [PATCH] Incorrect detection of datetime values Fixes #3673 --- .../install/files/js/WoltLabSuite/Core/Date/Picker.js | 9 +++++++-- .../install/files/ts/WoltLabSuite/Core/Date/Picker.ts | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js index 7c8458a8a5..2e2ee7e727 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js @@ -528,7 +528,8 @@ define(["require", "exports", "tslib", "../Core", "./Util", "../Dom/Change/Liste .forEach((element) => { element.classList.add("inputDatePicker"); element.readOnly = true; - const isDateTime = element.type === "datetime"; + // Use `getAttribute()`, because `.type` is normalized to "text" for unknown values. + const isDateTime = element.getAttribute("type") === "datetime"; const isTimeOnly = isDateTime && Core.stringToBool(element.dataset.timeOnly || ""); const disableClear = Core.stringToBool(element.dataset.disableClear || ""); const ignoreTimezone = isDateTime && Core.stringToBool(element.dataset.ignoreTimezone || ""); @@ -538,6 +539,10 @@ define(["require", "exports", "tslib", "../Core", "./Util", "../Dom/Change/Liste // convert value let date = null; let value = element.value; + if (!value) { + // Some legacy code may incorrectly use `setAttribute("value", value)`. + value = element.getAttribute("value") || ""; + } // ignore the timezone, if the value is only a date (YYYY-MM-DD) const isDateOnly = /^\d+-\d+-\d+$/.test(value); if (value) { @@ -790,7 +795,7 @@ define(["require", "exports", "tslib", "../Core", "./Util", "../Dom/Change/Liste const container = element.parentNode; container.parentNode.insertBefore(element, container); container.remove(); - element.type = "date" + (data.isDateTime ? "time" : ""); + element.setAttribute("type", "date" + (data.isDateTime ? "time" : "")); element.name = data.shadow.name; element.value = data.shadow.value; element.removeAttribute("data-value"); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Date/Picker.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Date/Picker.ts index 9c5c304a9b..2abc9b64bf 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Date/Picker.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Date/Picker.ts @@ -643,7 +643,8 @@ const DatePicker = { element.classList.add("inputDatePicker"); element.readOnly = true; - const isDateTime = element.type === "datetime"; + // Use `getAttribute()`, because `.type` is normalized to "text" for unknown values. + const isDateTime = element.getAttribute("type") === "datetime"; const isTimeOnly = isDateTime && Core.stringToBool(element.dataset.timeOnly || ""); const disableClear = Core.stringToBool(element.dataset.disableClear || ""); const ignoreTimezone = isDateTime && Core.stringToBool(element.dataset.ignoreTimezone || ""); @@ -655,6 +656,10 @@ const DatePicker = { // convert value let date: Date | null = null; let value = element.value; + if (!value) { + // Some legacy code may incorrectly use `setAttribute("value", value)`. + value = element.getAttribute("value") || ""; + } // ignore the timezone, if the value is only a date (YYYY-MM-DD) const isDateOnly = /^\d+-\d+-\d+$/.test(value); @@ -951,7 +956,7 @@ const DatePicker = { container.parentNode!.insertBefore(element, container); container.remove(); - element.type = "date" + (data.isDateTime ? "time" : ""); + element.setAttribute("type", "date" + (data.isDateTime ? "time" : "")); element.name = data.shadow.name; element.value = data.shadow.value; -- 2.20.1