From addc04ffb709d125a9a6c56cd9c0df61c3de8045 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Tue, 18 May 2021 07:01:42 +0200 Subject: [PATCH] Properly position errors below fields in `.inputAddon` elements --- ts/WoltLabSuite/Core/Dom/Util.ts | 11 +++++++++-- .../install/files/js/WoltLabSuite/Core/Dom/Util.js | 10 ++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ts/WoltLabSuite/Core/Dom/Util.ts b/ts/WoltLabSuite/Core/Dom/Util.ts index 838c52b4ca..8170042606 100644 --- a/ts/WoltLabSuite/Core/Dom/Util.ts +++ b/ts/WoltLabSuite/Core/Dom/Util.ts @@ -449,14 +449,21 @@ const DomUtil = { } } - let innerError = element.nextElementSibling as HTMLElement | null; + let insertTarget = parent as HTMLElement; + let referenceElement = element; + if (insertTarget.classList.contains('inputAddon')) { + insertTarget = parent.parentElement as HTMLElement; + referenceElement = parent as HTMLElement; + } + + let innerError = referenceElement.nextElementSibling as HTMLElement | null; if (innerError === null || innerError.nodeName !== "SMALL" || !innerError.classList.contains("innerError")) { if (errorMessage === "") { innerError = null; } else { innerError = document.createElement("small"); innerError.className = "innerError"; - parent.insertBefore(innerError, element.nextSibling); + insertTarget.insertBefore(innerError, referenceElement.nextSibling); } } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js index 49f7a0ed7f..c3f078b080 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js @@ -380,7 +380,13 @@ define(["require", "exports", "tslib", "../StringUtil"], function (require, expo throw new TypeError("The error message must be a string; `false`, `null` or `undefined` can be used as a substitute for an empty string."); } } - let innerError = element.nextElementSibling; + let insertTarget = parent; + let referenceElement = element; + if (insertTarget.classList.contains('inputAddon')) { + insertTarget = parent.parentElement; + referenceElement = parent; + } + let innerError = referenceElement.nextElementSibling; if (innerError === null || innerError.nodeName !== "SMALL" || !innerError.classList.contains("innerError")) { if (errorMessage === "") { innerError = null; @@ -388,7 +394,7 @@ define(["require", "exports", "tslib", "../StringUtil"], function (require, expo else { innerError = document.createElement("small"); innerError.className = "innerError"; - parent.insertBefore(innerError, element.nextSibling); + insertTarget.insertBefore(innerError, referenceElement.nextSibling); } } if (errorMessage === "") { -- 2.20.1