@@ -71,10 +71,24 @@ export function CodeSnippetInputDialog(
7171 }
7272 }
7373
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 > {
7489 return showCodeSnippetForm ( {
7590 title : 'Save Code Snippet' ,
76- body : new InputHandler ( tags ) ,
77- // focusNodeSelector: 'input',
91+ body : body ,
7892 buttons : [
7993 CodeSnippetForm . cancelButton ( ) ,
8094 CodeSnippetForm . okButton ( { label : 'Save' } )
@@ -87,15 +101,15 @@ export function CodeSnippetInputDialog(
87101 console . log ( idx ) ;
88102
89103 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 ) ;
91105 } else {
92106 // if (idx === -1) {
93107 // idx = codeSnippetWidget.codeSnippetWidgetModel.snippets.length;
94108 // }
95109
96110 const tags = result . value . slice ( 3 ) ;
97111 const newSnippet : ICodeSnippet = {
98- name : result . value [ 0 ] . replace ( ' ' , '' ) . toLowerCase ( ) ,
112+ name : result . value [ 0 ] . replace ( ' ' , '' ) ,
99113 description : result . value [ 1 ] ,
100114 language : result . value [ 2 ] ,
101115 code : code ,
@@ -109,7 +123,7 @@ export function CodeSnippetInputDialog(
109123 snippet ,
110124 newSnippet
111125 ) ;
112-
126+ console . log ( 'uh reached here' ) ;
113127 result
114128 . then ( newSnippets => {
115129 codeSnippetWidget . renderCodeSnippetsSignal . emit ( newSnippets ) ;
@@ -238,20 +252,18 @@ export function validateForm(
238252 message += 'Name must be filled out\n' ;
239253 status = false ;
240254 }
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
242257 message += 'Wrong format of the name\n' ;
243258 status = false ;
244259 }
245- if ( description === '' ) {
246- message += 'Description must be filled out\n' ;
247- status = false ;
248- }
249260 if ( description . match ( / [ ^ a - z A - Z 0 - 9 _ , . ? ! ] + / ) ) {
261+ //alphanumeric but can include space or punctuation
250262 message += 'Wrong format of the description\n' ;
251263 status = false ;
252264 }
253265 if ( language === '' ) {
254- message += 'Language must be filled out' ;
266+ message += 'Language must be filled out\n ' ;
255267 status = false ;
256268 }
257269 if ( ! SUPPORTED_LANGUAGES . includes ( language ) ) {
@@ -321,7 +333,7 @@ class Private {
321333 const body = document . createElement ( 'form' ) ;
322334 const nameValidity = document . createElement ( 'p' ) ;
323335 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(_)' ;
325337 nameValidity . className = CODE_SNIPPET_INPUTNAME_VALIDITY ;
326338
327339 const descriptionValidity = document . createElement ( 'p' ) ;
@@ -338,10 +350,9 @@ class Private {
338350 name . onblur = Private . handleOnBlur ;
339351
340352 const descriptionTitle = document . createElement ( 'label' ) ;
341- descriptionTitle . textContent = 'Description (required )' ;
353+ descriptionTitle . textContent = 'Description (optional )' ;
342354 const description = document . createElement ( 'input' ) ;
343355 description . className = CODE_SNIPPET_DIALOG_INPUT ;
344- description . required = true ;
345356 description . pattern = '[a-zA-Z0-9_ ,.?!]+' ;
346357 description . onblur = Private . handleOnBlur ;
347358
0 commit comments