From 016a441d3276ed212d37ca0f4111f055de0ab756 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Tue, 7 Apr 2026 09:31:45 +0700 Subject: [PATCH] fix: patch PDFIframe to strip trailing whitespace nodes during sign item rendering --- static/src/js/sign_image_upload.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/static/src/js/sign_image_upload.js b/static/src/js/sign_image_upload.js index fe9162c..ddd81a4 100755 --- a/static/src/js/sign_image_upload.js +++ b/static/src/js/sign_image_upload.js @@ -213,3 +213,29 @@ patch(SignablePDFIframe.prototype, { return super.getSignatureValueFromElement(...arguments); } }); + +/** + * FIX: Odoo Core Bug where trailing whitespace on custom items causes target.lastChild to be a Text Node. + * This patch intercepts the insertAdjacentHTML during renderSignItem to strip trailing whitespace nodes immediately, + * without modifying Odoo Enterprise source code. + */ +patch(PDFIframe.prototype, { + renderSignItem(signItemData, target) { + if (target && target.insertAdjacentHTML) { + const originalInsert = target.insertAdjacentHTML; + target.insertAdjacentHTML = function(position, text) { + originalInsert.call(this, position, text.trim()); + // Remove trailing whitespace nodes injected by QWeb + while (this.lastChild && this.lastChild.nodeType !== 1) { // 1 == ELEMENT_NODE + this.lastChild.remove(); + } + }; + try { + return super.renderSignItem(...arguments); + } finally { + target.insertAdjacentHTML = originalInsert; + } + } + return super.renderSignItem(...arguments); + } +});