From 1dc7f5338623ec97d9ea395380270470847a0066 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sat, 9 Mar 2024 13:59:16 +0200 Subject: [PATCH] Fix WebHookEditor regression from jQuery removal (#29692) Make these calls optional --------- Signed-off-by: Yarden Shoham Co-authored-by: wxiaoguang --- web_src/js/features/comp/WebHookEditor.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/web_src/js/features/comp/WebHookEditor.js b/web_src/js/features/comp/WebHookEditor.js index 86d21dc81..b7ca5a0fc 100644 --- a/web_src/js/features/comp/WebHookEditor.js +++ b/web_src/js/features/comp/WebHookEditor.js @@ -22,13 +22,16 @@ export function initCompWebHookEditor() { }); } - const updateContentType = function () { - const visible = document.getElementById('http_method').value === 'POST'; - toggleElem(document.getElementById('content_type').parentNode.parentNode, visible); - }; - updateContentType(); - - document.getElementById('http_method').addEventListener('change', updateContentType); + // some webhooks (like Gitea) allow to set the request method (GET/POST), and it would toggle the "Content Type" field + const httpMethodInput = document.getElementById('http_method'); + if (httpMethodInput) { + const updateContentType = function () { + const visible = httpMethodInput.value === 'POST'; + toggleElem(document.getElementById('content_type').closest('.field'), visible); + }; + updateContentType(); + httpMethodInput.addEventListener('change', updateContentType); + } // Test delivery document.getElementById('test-delivery')?.addEventListener('click', async function () {