From 6a56036782bed089895567c6def6e09b3dff7558 Mon Sep 17 00:00:00 2001 From: Alex Mickelson Date: Wed, 22 Oct 2025 09:21:40 -0600 Subject: [PATCH] name validation --- .../[courseName]/modules/NewItemForm.tsx | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/app/course/[courseName]/modules/NewItemForm.tsx b/src/app/course/[courseName]/modules/NewItemForm.tsx index 4dc706f..b4d0d64 100644 --- a/src/app/course/[courseName]/modules/NewItemForm.tsx +++ b/src/app/course/[courseName]/modules/NewItemForm.tsx @@ -39,6 +39,27 @@ export default function NewItemForm({ ); const [name, setName] = useState(""); + const [nameError, setNameError] = useState(""); + + const validateFileName = (fileName: string): string => { + // Check for invalid file system characters + const invalidChars = [":", "/", "\\", "*", '"', "<", ">", "|"]; + + for (const char of fileName) { + if (invalidChars.includes(char)) { + return `Name contains invalid character: "${char}". Please avoid: ${invalidChars.join( + " " + )}`; + } + } + return ""; + }; + + const handleNameChange = (newName: string) => { + setName(newName); + const error = validateFileName(newName); + setNameError(error); + }; const defaultDate = getDateFromString( creationDate ? creationDate : dateToMarkdownString(new Date()) @@ -65,6 +86,12 @@ export default function NewItemForm({ className="flex flex-col gap-3" onSubmit={(e) => { e.preventDefault(); + + // Validate name before submission + if (nameError) { + return; + } + const dueAt = dueDate === "" ? dueDate @@ -160,7 +187,16 @@ export default function NewItemForm({ />
- + + {nameError && ( +
+ {nameError} +
+ )}
{type !== "Page" && ( @@ -178,7 +214,9 @@ export default function NewItemForm({ No assignment groups created, create them in the course settings page
)} - + {isPending && } );