@@ -256,8 +256,42 @@ const addSample = (curationMode) => {
256
256
let sampleID = "" ;
257
257
let subjectID = "" ;
258
258
if ( curationMode === "free-form" ) {
259
- sampleID = $ ( "#bootbox-sample-id" ) . val ( ) ;
260
- subjectID = $ ( "#bootbox-subject-id-samples" ) . val ( ) ;
259
+ sampleID = $ ( "#bootbox-sample-id" ) . val ( ) . trim ( ) ;
260
+ subjectID = $ ( "#bootbox-subject-id-samples" ) . val ( ) . trim ( ) ;
261
+ if ( sampleID === "" || subjectID === "" ) {
262
+ notyf . open ( {
263
+ type : "error" ,
264
+ message : "The subject_id and sample_id are required to add a sample." ,
265
+ duration : 3000 ,
266
+ } ) ;
267
+ return ;
268
+ }
269
+
270
+ const sampleNameIsValid = evaluateStringAgainstSdsRequirements (
271
+ sampleID ,
272
+ "string-adheres-to-identifier-conventions"
273
+ ) ;
274
+ if ( ! sampleNameIsValid ) {
275
+ notyf . open ( {
276
+ type : "error" ,
277
+ message : "The sample_id can not contain special characters." ,
278
+ duration : 4000 ,
279
+ } ) ;
280
+ return ;
281
+ }
282
+ const subjectNameIsValid = evaluateStringAgainstSdsRequirements (
283
+ subjectID ,
284
+ "string-adheres-to-identifier-conventions"
285
+ ) ;
286
+ if ( ! subjectNameIsValid ) {
287
+ notyf . open ( {
288
+ type : "error" ,
289
+ message : "The subject_id can not contain special characters." ,
290
+ duration : 4000 ,
291
+ } ) ;
292
+ return ;
293
+ }
294
+
261
295
addSampleIDtoDataBase ( sampleID , subjectID ) ;
262
296
if ( samplesTableData . length !== 0 ) {
263
297
$ ( "#div-import-primary-folder-samples" ) . hide ( ) ;
@@ -457,17 +491,14 @@ const addSampleIDtoDataBase = (samID, subID) => {
457
491
break ;
458
492
}
459
493
}
460
- if ( samID !== "" && subID !== "" ) {
461
- if ( ! duplicate ) {
462
- var message = addNewIDToTable ( samID , subID , "samples" ) ;
463
- addSampleIDtoJSON ( samID ) ;
464
- } else {
465
- error =
466
- "A similar sample_id already exists. Please either delete the existing sample_id or choose a different sample_id." ;
467
- }
494
+ if ( ! duplicate ) {
495
+ var message = addNewIDToTable ( samID , subID , "samples" ) ;
496
+ addSampleIDtoJSON ( samID ) ;
468
497
} else {
469
- error = "The subject_id and sample_id are required to add a sample." ;
498
+ error =
499
+ "A similar sample_id already exists. Please either delete the existing sample_id or choose a different sample_id." ;
470
500
}
501
+
471
502
if ( error !== "" ) {
472
503
Swal . fire ( "Failed to add the sample" , error , "error" ) ;
473
504
}
0 commit comments