@@ -71,10 +71,24 @@ export function CodeSnippetInputDialog(
71
71
}
72
72
}
73
73
74
+ const body : InputHandler = new InputHandler ( tags ) ;
75
+
76
+ return showInputDialog ( tags , idx , codeSnippetWidget , code , body ) ;
77
+ }
78
+
79
+ /**
80
+ * This function creates the actual input form and processes the inputs given.
81
+ */
82
+ export function showInputDialog (
83
+ tags : string [ ] ,
84
+ idx : number ,
85
+ codeSnippetWidget : CodeSnippetWidget ,
86
+ code : string [ ] ,
87
+ body : InputHandler
88
+ ) : Promise < Contents . IModel | null > {
74
89
return showCodeSnippetForm ( {
75
90
title : 'Save Code Snippet' ,
76
- body : new InputHandler ( tags ) ,
77
- // focusNodeSelector: 'input',
91
+ body : body ,
78
92
buttons : [
79
93
CodeSnippetForm . cancelButton ( ) ,
80
94
CodeSnippetForm . okButton ( { label : 'Save' } )
@@ -87,15 +101,15 @@ export function CodeSnippetInputDialog(
87
101
console . log ( idx ) ;
88
102
89
103
if ( validateForm ( result ) === false ) {
90
- return CodeSnippetInputDialog ( codeSnippetWidget , code , idx ) ; // This works but it wipes out all the data they entered previously...
104
+ showInputDialog ( tags , idx , codeSnippetWidget , code , body ) ;
91
105
} else {
92
106
// if (idx === -1) {
93
107
// idx = codeSnippetWidget.codeSnippetWidgetModel.snippets.length;
94
108
// }
95
109
96
110
const tags = result . value . slice ( 3 ) ;
97
111
const newSnippet : ICodeSnippet = {
98
- name : result . value [ 0 ] . replace ( ' ' , '' ) . toLowerCase ( ) ,
112
+ name : result . value [ 0 ] . replace ( ' ' , '' ) ,
99
113
description : result . value [ 1 ] ,
100
114
language : result . value [ 2 ] ,
101
115
code : code ,
@@ -109,7 +123,7 @@ export function CodeSnippetInputDialog(
109
123
snippet ,
110
124
newSnippet
111
125
) ;
112
-
126
+ console . log ( 'uh reached here' ) ;
113
127
result
114
128
. then ( newSnippets => {
115
129
codeSnippetWidget . renderCodeSnippetsSignal . emit ( newSnippets ) ;
@@ -238,20 +252,18 @@ export function validateForm(
238
252
message += 'Name must be filled out\n' ;
239
253
status = false ;
240
254
}
241
- if ( name . match ( / [ ^ a - z 0 - 9 _ ] + / ) ) {
255
+ if ( name . match ( / [ ^ a - z A - Z 0 - 9 _ ] + / ) ) {
256
+ //allow lowercase, uppercase, alphanumeric, and underscore
242
257
message += 'Wrong format of the name\n' ;
243
258
status = false ;
244
259
}
245
- if ( description === '' ) {
246
- message += 'Description must be filled out\n' ;
247
- status = false ;
248
- }
249
260
if ( description . match ( / [ ^ a - z A - Z 0 - 9 _ , . ? ! ] + / ) ) {
261
+ //alphanumeric but can include space or punctuation
250
262
message += 'Wrong format of the description\n' ;
251
263
status = false ;
252
264
}
253
265
if ( language === '' ) {
254
- message += 'Language must be filled out' ;
266
+ message += 'Language must be filled out\n ' ;
255
267
status = false ;
256
268
}
257
269
if ( ! SUPPORTED_LANGUAGES . includes ( language ) ) {
@@ -321,7 +333,7 @@ class Private {
321
333
const body = document . createElement ( 'form' ) ;
322
334
const nameValidity = document . createElement ( 'p' ) ;
323
335
nameValidity . textContent =
324
- 'Name of the code snippet MUST be lowercased, alphanumeric, or composed of underscore(_)' ;
336
+ 'Name of the code snippet MUST be alphanumeric, or composed of underscore(_)' ;
325
337
nameValidity . className = CODE_SNIPPET_INPUTNAME_VALIDITY ;
326
338
327
339
const descriptionValidity = document . createElement ( 'p' ) ;
@@ -338,10 +350,9 @@ class Private {
338
350
name . onblur = Private . handleOnBlur ;
339
351
340
352
const descriptionTitle = document . createElement ( 'label' ) ;
341
- descriptionTitle . textContent = 'Description (required )' ;
353
+ descriptionTitle . textContent = 'Description (optional )' ;
342
354
const description = document . createElement ( 'input' ) ;
343
355
description . className = CODE_SNIPPET_DIALOG_INPUT ;
344
- description . required = true ;
345
356
description . pattern = '[a-zA-Z0-9_ ,.?!]+' ;
346
357
description . onblur = Private . handleOnBlur ;
347
358
0 commit comments