Skip to content

Commit 0c4ff01

Browse files
kemzebwxiaoguang
andauthored
Disable issue/PR comment button given empty input (#31463)
Given an empty issue/PR comment, the comment history would not be updated if the user were to submit it. Therefore, it would make since to just disable the comment button when the text editor is empty. This is inline with what GitHub does when given empty text editor input. --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent f4921b9 commit 0c4ff01

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

templates/repo/issue/view_content.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
</button>
107107
{{end}}
108108
{{end}}
109-
<button class="ui primary button">
109+
<button id="comment-button" class="ui primary button">
110110
{{ctx.Locale.Tr "repo.issues.create_comment"}}
111111
</button>
112112
</div>

web_src/js/features/repo-issue.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import $ from 'jquery';
22
import {htmlEscape} from 'escape-goat';
3-
import {showTemporaryTooltip, createTippy} from '../modules/tippy.js';
3+
import {createTippy, showTemporaryTooltip} from '../modules/tippy.js';
44
import {hideElem, showElem, toggleElem} from '../utils/dom.js';
55
import {setFileFolding} from './file-fold.js';
66
import {getComboMarkdownEditor, initComboMarkdownEditor} from './comp/ComboMarkdownEditor.js';
77
import {toAbsoluteUrl} from '../utils.js';
88
import {initDropzone} from './dropzone.js';
9-
import {POST, GET} from '../modules/fetch.js';
9+
import {GET, POST} from '../modules/fetch.js';
1010
import {showErrorToast} from '../modules/toast.js';
1111

1212
const {appSubUrl} = window.config;
@@ -673,19 +673,24 @@ export function initRepoIssueBranchSelect() {
673673
});
674674
}
675675

676-
export function initSingleCommentEditor($commentForm) {
676+
export async function initSingleCommentEditor($commentForm) {
677677
// pages:
678-
// * normal new issue/pr page, no status-button
679-
// * issue/pr view page, with comment form, has status-button
678+
// * normal new issue/pr page: no status-button, no comment-button (there is only a normal submit button which can submit empty content)
679+
// * issue/pr view page: with comment form, has status-button and comment-button
680680
const opts = {};
681681
const statusButton = document.querySelector('#status-button');
682-
if (statusButton) {
683-
opts.onContentChanged = (editor) => {
684-
const statusText = statusButton.getAttribute(editor.value().trim() ? 'data-status-and-comment' : 'data-status');
685-
statusButton.textContent = statusText;
686-
};
687-
}
688-
initComboMarkdownEditor($commentForm.find('.combo-markdown-editor'), opts);
682+
const commentButton = document.querySelector('#comment-button');
683+
opts.onContentChanged = (editor) => {
684+
const editorText = editor.value().trim();
685+
if (statusButton) {
686+
statusButton.textContent = statusButton.getAttribute(editorText ? 'data-status-and-comment' : 'data-status');
687+
}
688+
if (commentButton) {
689+
commentButton.disabled = !editorText;
690+
}
691+
};
692+
const editor = await initComboMarkdownEditor($commentForm.find('.combo-markdown-editor'), opts);
693+
opts.onContentChanged(editor); // sync state of buttons with the initial content
689694
}
690695

691696
export function initIssueTemplateCommentEditors($commentForm) {

0 commit comments

Comments
 (0)