Suppress errors when the query for search suggestion fail
authorAlexander Ebert <ebert@woltlab.com>
Mon, 29 May 2023 12:41:52 +0000 (14:41 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 29 May 2023 12:41:52 +0000 (14:41 +0200)
See https://www.woltlab.com/community/thread/299875-suppress-errors-if-requests-for-search-suggestions-fail/

ts/WoltLabSuite/Core/Ui/Search/Data.ts
ts/WoltLabSuite/Core/Ui/Search/Input.ts
ts/WoltLabSuite/Core/Ui/Search/Page.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Search/Input.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Search/Page.js

index 11f0890e50a0471941691916345d9bb920326819..587b68a08f845a33311562f6c45a25fd30325cd7 100644 (file)
@@ -18,4 +18,5 @@ export interface SearchInputOptions {
   minLength?: number;
   noResultPlaceholder?: string;
   preventSubmit?: boolean;
+  suppressErrors?: boolean;
 }
index 09b1e1a81b3de40c4293a0cb996d51cbf4471a13..ea16ceb5dfd9177f6b29479c6371b7a6bc182cac 100644 (file)
@@ -30,6 +30,7 @@ class UiSearchInput {
   private readonly noResultPlaceholder: string;
   private readonly preventSubmit: boolean;
   private request?: AjaxRequest = undefined;
+  private readonly suppressErrors: boolean;
   private timerDelay?: number = undefined;
 
   /**
@@ -61,6 +62,7 @@ class UiSearchInput {
         minLength: 3,
         noResultPlaceholder: "",
         preventSubmit: false,
+        suppressErrors: false,
       },
       options,
     ) as SearchInputOptions;
@@ -76,6 +78,7 @@ class UiSearchInput {
     this.minLength = options.minLength!;
     this.noResultPlaceholder = options.noResultPlaceholder!;
     this.preventSubmit = options.preventSubmit!;
+    this.suppressErrors = options.suppressErrors || false;
 
     // Disable auto-complete because it collides with the suggestion dropdown.
     this.element.autocomplete = "off";
@@ -359,6 +362,7 @@ class UiSearchInput {
   _ajaxSetup(): ReturnType<AjaxCallbackSetup> {
     return {
       data: this.ajaxPayload,
+      silent: this.suppressErrors,
     };
   }
 }
index 7c9dc4863e82bddb38ded54c7e2ddcdf3b2e4ac4..712a48fdbb82bde950d0fd6532525b4380b4d4c3 100644 (file)
@@ -82,6 +82,7 @@ export function init(objectType: string): void {
 
       return true;
     },
+    suppressErrors: true,
   });
 
   const searchType = document.querySelector(".pageHeaderSearchType") as HTMLElement;
index e8cf9d7527b7ecb4edf9e1d9199650a0e83410ed..5ee13784b60d0c24edac943a8373b3d3fa43881d 100644 (file)
@@ -27,6 +27,7 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Ut
         noResultPlaceholder;
         preventSubmit;
         request = undefined;
+        suppressErrors;
         timerDelay = undefined;
         /**
          * Initializes the search input field.
@@ -56,6 +57,7 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Ut
                 minLength: 3,
                 noResultPlaceholder: "",
                 preventSubmit: false,
+                suppressErrors: false,
             }, options);
             this.ajaxPayload = options.ajax;
             this.autoFocus = options.autoFocus;
@@ -68,6 +70,7 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Ut
             this.minLength = options.minLength;
             this.noResultPlaceholder = options.noResultPlaceholder;
             this.preventSubmit = options.preventSubmit;
+            this.suppressErrors = options.suppressErrors || false;
             // Disable auto-complete because it collides with the suggestion dropdown.
             this.element.autocomplete = "off";
             this.element.addEventListener("keydown", (ev) => this.keydown(ev));
@@ -306,6 +309,7 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Ut
         _ajaxSetup() {
             return {
                 data: this.ajaxPayload,
+                silent: this.suppressErrors,
             };
         }
     }
index 25a613cfce0bb1e88b32e1543118a2bc752578cb..15c19f0c4f5ef86c963f54342769b9a414245eb2 100644 (file)
@@ -66,6 +66,7 @@ define(["require", "exports", "tslib", "../../Core", "../../Dom/Util", "../Dropd
                 }, 1);
                 return true;
             },
+            suppressErrors: true,
         });
         const searchType = document.querySelector(".pageHeaderSearchType");
         const dropdownMenu = Simple_1.default.getDropdownMenu(Util_1.default.identify(searchType));