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({ />