Skip to content

Commit 86fbb0e

Browse files
committed
fix: 🐛 fixed sample name inputs for ffm sample metadata
1 parent 47f296c commit 86fbb0e

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

scripts/metadata-files/subjects-samples.js

+42-11
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,42 @@ const addSample = (curationMode) => {
256256
let sampleID = "";
257257
let subjectID = "";
258258
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+
261295
addSampleIDtoDataBase(sampleID, subjectID);
262296
if (samplesTableData.length !== 0) {
263297
$("#div-import-primary-folder-samples").hide();
@@ -457,17 +491,14 @@ const addSampleIDtoDataBase = (samID, subID) => {
457491
break;
458492
}
459493
}
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);
468497
} 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.";
470500
}
501+
471502
if (error !== "") {
472503
Swal.fire("Failed to add the sample", error, "error");
473504
}

0 commit comments

Comments
 (0)