@@ -8,7 +8,9 @@ export function initRepoWikiForm() {
8
8
let sideBySideChanges = 0 ;
9
9
let sideBySideTimeout = null ;
10
10
let hasSimpleMDE = true ;
11
+
11
12
if ( $editArea . length > 0 ) {
13
+ const $form = $ ( '.repository.wiki.new .ui.form' ) ;
12
14
const simplemde = new SimpleMDE ( {
13
15
autoDownloadFontAwesome : false ,
14
16
element : $editArea [ 0 ] ,
@@ -105,7 +107,6 @@ export function initRepoWikiForm() {
105
107
action ( e ) {
106
108
e . toTextArea ( ) ;
107
109
hasSimpleMDE = false ;
108
- const $form = $ ( '.repository.wiki.new .ui.form' ) ;
109
110
const $root = $form . find ( '.field.content' ) ;
110
111
const loading = $root . data ( 'loading' ) ;
111
112
$root . append ( `<div class="ui bottom tab markup" data-tab="preview">${ loading } </div>` ) ;
@@ -117,23 +118,24 @@ export function initRepoWikiForm() {
117
118
]
118
119
} ) ;
119
120
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 ) {
121
125
// The original edit area HTML element is hidden and replaced by the
122
126
// SimpleMDE editor, breaking HTML5 input validation if the text area is empty.
123
127
// This is a workaround for this upstream bug.
124
128
// See https://github.com/sparksuite/simplemde-markdown-editor/issues/324
125
- const input = $editArea . val ( )
129
+ const input = $editArea . val ( ) ;
126
130
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 ( ) ;
130
134
} else {
131
- $ ( simplemde . codemirror . getInputField ( ) ) . attr ( 'required' , false ) ;
135
+ $markdownEditorTextArea . prop ( 'required' , false ) ;
132
136
}
133
137
} ) ;
134
138
135
- $ ( simplemde . codemirror . getInputField ( ) ) . addClass ( 'js-quick-submit' ) ;
136
-
137
139
setTimeout ( ( ) => {
138
140
const $bEdit = $ ( '.repository.wiki.new .previewtabs a[data-tab="write"]' ) ;
139
141
const $bPrev = $ ( '.repository.wiki.new .previewtabs a[data-tab="preview"]' ) ;
0 commit comments