diff --git a/src/lib/components/preparation/StudyForm.svelte b/src/lib/components/preparation/StudyForm.svelte index b89dfc5..1cba78b 100644 --- a/src/lib/components/preparation/StudyForm.svelte +++ b/src/lib/components/preparation/StudyForm.svelte @@ -87,36 +87,40 @@ // parse file content and set subject list to empty list in case of an error let el = document.getElementById('file'); if (el instanceof HTMLInputElement) { - if(el.files && el.files.length > 0){ + if(el.files && el.files.length > 0) { let file: File = el.files[0]; - parseFile(file).then((subjectList) => { - parsingError = ""; - studyProps.update((props) => { - return { + file.text().then((text) => { + let delimiter = text.includes(";") || text.includes(",") ? "" : " "; + parseFile(file, delimiter).then((subjectList) => { + parsingError = ""; + studyProps.update((props) => { + return { ...props, subjectList: subjectList, - }; - }); - }).catch((err) => { - parsingError = err; - studyProps.update((props) => { - return { + }; + }); + }).catch((err) => { + parsingError = err; + studyProps.update((props) => { + return { ...props, subjectList: [], - }; + }; + }); }); }); } } } - - function parseFile(file: File): Promise{ + + function parseFile(file: File, delimiter: String): Promise{ let subjectList: string [] = []; let err: string = ""; return new Promise((resolve, reject) => { Papa.parse(file, { header: true, skipEmptyLines: true, + delimiter: delimiter, complete: function(parsed: any) { let col = $studyProps.subjectColumn; if (col){