Datepicker was not prefilled correctly
authorMarcel Werk <burntime@woltlab.com>
Thu, 9 Dec 2021 16:08:07 +0000 (17:08 +0100)
committerMarcel Werk <burntime@woltlab.com>
Thu, 9 Dec 2021 16:08:07 +0000 (17:08 +0100)
ts/WoltLabSuite/Core/Ui/Search/Extended.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Search/Extended.js

index c53223ca5b34217d5c63e889ca0d70e020fc7de6..5afe23d5fb99f9d5775c9b4211f3aedd7b65e9a3 100644 (file)
@@ -1,4 +1,5 @@
 import { dboAction } from "../../Ajax";
+import DatePicker from "../../Date/Picker";
 import * as DomUtil from "../../Dom/Util";
 import { ucfirst } from "../../StringUtil";
 import UiPagination from "../Pagination";
@@ -78,7 +79,7 @@ export class UiSearchExtended {
     this.activePage = 1;
 
     this.removeSearchResults();
-    
+
     if (count > 0) {
       this.pages = pages!;
       this.showSearchResults(template!);
@@ -112,8 +113,27 @@ export class UiSearchExtended {
   private initQueryString(): void {
     const url = new URL(window.location.href);
     url.searchParams.forEach((value, key) => {
-      if (value && this.form.elements[key]) {
-        this.form.elements[key].value = value;
+      let element = this.form.elements[key] as HTMLElement;
+      if (value && element) {
+        if (element instanceof RadioNodeList) {
+          let id = "";
+          element.forEach((childElement: HTMLElement) => {
+            if (childElement.classList.contains("inputDatePicker")) {
+              id = childElement.id;
+            }
+          });
+          if (id) {
+            DatePicker.setDate(id, new Date(value));
+          }
+        } else if (element instanceof HTMLInputElement) {
+          if (element.type === "checkbox") {
+            element.checked = true;
+          } else {
+            element.value = value;
+          }
+        } else if (element instanceof HTMLSelectElement) {
+          element.value = value;
+        }
       }
     });
 
index 0ded99d7b5a0c499a716c2e453daf45d53e6f0ee..f9e06e710349f4b2205aa7b356e2635862fd5706 100644 (file)
@@ -1,7 +1,8 @@
-define(["require", "exports", "tslib", "../../Ajax", "../../Dom/Util", "../../StringUtil", "../Pagination", "./Input"], function (require, exports, tslib_1, Ajax_1, DomUtil, StringUtil_1, Pagination_1, Input_1) {
+define(["require", "exports", "tslib", "../../Ajax", "../../Date/Picker", "../../Dom/Util", "../../StringUtil", "../Pagination", "./Input"], function (require, exports, tslib_1, Ajax_1, Picker_1, DomUtil, StringUtil_1, Pagination_1, Input_1) {
     "use strict";
     Object.defineProperty(exports, "__esModule", { value: true });
     exports.UiSearchExtended = void 0;
+    Picker_1 = (0, tslib_1.__importDefault)(Picker_1);
     DomUtil = (0, tslib_1.__importStar)(DomUtil);
     Pagination_1 = (0, tslib_1.__importDefault)(Pagination_1);
     Input_1 = (0, tslib_1.__importDefault)(Input_1);
@@ -80,8 +81,30 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Dom/Util", "../../St
         initQueryString() {
             const url = new URL(window.location.href);
             url.searchParams.forEach((value, key) => {
-                if (value && this.form.elements[key]) {
-                    this.form.elements[key].value = value;
+                let element = this.form.elements[key];
+                if (value && element) {
+                    if (element instanceof RadioNodeList) {
+                        let id = "";
+                        element.forEach((childElement) => {
+                            if (childElement.classList.contains("inputDatePicker")) {
+                                id = childElement.id;
+                            }
+                        });
+                        if (id) {
+                            Picker_1.default.setDate(id, new Date(value));
+                        }
+                    }
+                    else if (element instanceof HTMLInputElement) {
+                        if (element.type === "checkbox") {
+                            element.checked = true;
+                        }
+                        else {
+                            element.value = value;
+                        }
+                    }
+                    else if (element instanceof HTMLSelectElement) {
+                        element.value = value;
+                    }
                 }
             });
             this.typeInput.dispatchEvent(new Event("change"));