From e2790d5952519fb9881ce4c3c0b769bcfba2f8bc Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 15 Aug 2023 19:31:48 +0800 Subject: [PATCH] Set "type=button" for editor's toolbar buttons (#26510) The editor usually is in a form, so the buttons should have "type=button", avoid conflicting with the form's submit. --- web_src/js/features/comp/ComboMarkdownEditor.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web_src/js/features/comp/ComboMarkdownEditor.js b/web_src/js/features/comp/ComboMarkdownEditor.js index 48e3ca5bd24c2..4ea7c3e63af6b 100644 --- a/web_src/js/features/comp/ComboMarkdownEditor.js +++ b/web_src/js/features/comp/ComboMarkdownEditor.js @@ -78,6 +78,8 @@ class ComboMarkdownEditor { for (const el of this.textareaMarkdownToolbar.querySelectorAll('.markdown-toolbar-button')) { // upstream bug: The role code is never executed in base MarkdownButtonElement https://github.com/github/markdown-toolbar-element/issues/70 el.setAttribute('role', 'button'); + // the editor usually is in a form, so the buttons should have "type=button", avoiding conflicting with the form's submit. + if (el.nodeName === 'BUTTON' && !el.getAttribute('type')) el.setAttribute('type', 'button'); } const monospaceButton = this.container.querySelector('.markdown-switch-monospace');