]> source.dussan.org Git - gitea.git/commitdiff
Set "type=button" for editor's toolbar buttons (#26510) (#26518)
authorGiteabot <teabot@gitea.io>
Tue, 15 Aug 2023 12:10:50 +0000 (20:10 +0800)
committerGitHub <noreply@github.com>
Tue, 15 Aug 2023 12:10:50 +0000 (14:10 +0200)
Backport #26510 by @wxiaoguang

The editor usually is in a form, so the buttons should have
"type=button", avoid conflicting with the form's submit.

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
web_src/js/features/comp/ComboMarkdownEditor.js

index 48e3ca5bd24c2b1716acc52a1d0242bb2ce268b4..4ea7c3e63af6b3fcda3973255b6c5659b0fa9ca5 100644 (file)
@@ -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');