aboutsummaryrefslogtreecommitdiffstats
path: root/web_src
diff options
context:
space:
mode:
Diffstat (limited to 'web_src')
-rw-r--r--web_src/js/features/repo-wiki.js22
1 files changed, 20 insertions, 2 deletions
diff --git a/web_src/js/features/repo-wiki.js b/web_src/js/features/repo-wiki.js
index ddd4e30a8a..1acdb4da48 100644
--- a/web_src/js/features/repo-wiki.js
+++ b/web_src/js/features/repo-wiki.js
@@ -8,7 +8,9 @@ export function initRepoWikiForm() {
let sideBySideChanges = 0;
let sideBySideTimeout = null;
let hasSimpleMDE = true;
+
if ($editArea.length > 0) {
+ const $form = $('.repository.wiki.new .ui.form');
const simplemde = new SimpleMDE({
autoDownloadFontAwesome: false,
element: $editArea[0],
@@ -105,7 +107,6 @@ export function initRepoWikiForm() {
action(e) {
e.toTextArea();
hasSimpleMDE = false;
- const $form = $('.repository.wiki.new .ui.form');
const $root = $form.find('.field.content');
const loading = $root.data('loading');
$root.append(`<div class="ui bottom tab markup" data-tab="preview">${loading}</div>`);
@@ -116,7 +117,24 @@ export function initRepoWikiForm() {
},
]
});
- $(simplemde.codemirror.getInputField()).addClass('js-quick-submit');
+
+ const $markdownEditorTextArea = $(simplemde.codemirror.getInputField());
+ $markdownEditorTextArea.addClass('js-quick-submit');
+
+ $form.on('submit', function (e) {
+ // The original edit area HTML element is hidden and replaced by the
+ // SimpleMDE editor, breaking HTML5 input validation if the text area is empty.
+ // This is a workaround for this upstream bug.
+ // See https://github.com/sparksuite/simplemde-markdown-editor/issues/324
+ const input = $editArea.val();
+ if (!input.length) {
+ e.preventDefault();
+ $markdownEditorTextArea.prop('required', true);
+ this.reportValidity();
+ } else {
+ $markdownEditorTextArea.prop('required', false);
+ }
+ });
setTimeout(() => {
const $bEdit = $('.repository.wiki.new .previewtabs a[data-tab="write"]');