Skip to content

Commit 39da7c2

Browse files
committed
refactor: extract variables and minor lint fixes
Signed-off-by: David Jimenez <[email protected]>
1 parent 531311f commit 39da7c2

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

templates/repo/wiki/new.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</div>
1212
{{end}}
1313
</div>
14-
<form id="edit_form" class="ui form" action="{{.Link}}" method="post">
14+
<form class="ui form" action="{{.Link}}" method="post">
1515
{{.CsrfTokenHtml}}
1616
<div class="field {{if .Err_Title}}error{{end}}">
1717
<input name="title" value="{{.title}}" autofocus required>

web_src/js/features/repo-wiki.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export function initRepoWikiForm() {
88
let sideBySideChanges = 0;
99
let sideBySideTimeout = null;
1010
let hasSimpleMDE = true;
11+
1112
if ($editArea.length > 0) {
13+
const $form = $('.repository.wiki.new .ui.form');
1214
const simplemde = new SimpleMDE({
1315
autoDownloadFontAwesome: false,
1416
element: $editArea[0],
@@ -105,7 +107,6 @@ export function initRepoWikiForm() {
105107
action(e) {
106108
e.toTextArea();
107109
hasSimpleMDE = false;
108-
const $form = $('.repository.wiki.new .ui.form');
109110
const $root = $form.find('.field.content');
110111
const loading = $root.data('loading');
111112
$root.append(`<div class="ui bottom tab markup" data-tab="preview">${loading}</div>`);
@@ -117,23 +118,24 @@ export function initRepoWikiForm() {
117118
]
118119
});
119120

120-
$('#edit_form').on('submit', (e) => {
121+
const $markdownEditorTextArea = $(simplemde.codemirror.getInputField());
122+
$markdownEditorTextArea.addClass('js-quick-submit');
123+
124+
$form.on('submit', function (e) {
121125
// The original edit area HTML element is hidden and replaced by the
122126
// SimpleMDE editor, breaking HTML5 input validation if the text area is empty.
123127
// This is a workaround for this upstream bug.
124128
// See https://github.com/sparksuite/simplemde-markdown-editor/issues/324
125-
const input = $editArea.val()
129+
const input = $editArea.val();
126130
if (!input.length) {
127-
$(simplemde.codemirror.getInputField()).attr('required', true);
128-
document.querySelector('#edit_form').reportValidity();
129-
e.preventDefault()
131+
e.preventDefault();
132+
$markdownEditorTextArea.prop('required', true);
133+
this.reportValidity();
130134
} else {
131-
$(simplemde.codemirror.getInputField()).attr('required', false);
135+
$markdownEditorTextArea.prop('required', false);
132136
}
133137
});
134138

135-
$(simplemde.codemirror.getInputField()).addClass('js-quick-submit');
136-
137139
setTimeout(() => {
138140
const $bEdit = $('.repository.wiki.new .previewtabs a[data-tab="write"]');
139141
const $bPrev = $('.repository.wiki.new .previewtabs a[data-tab="preview"]');

0 commit comments

Comments
 (0)