From 516e28e7ad6a41d759ed20d9e3dd4fbba166332a Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 22 Sep 2023 17:33:32 +0800 Subject: [PATCH] block invalid type file --- .../ApplyForm/PublicNoticeApplyForm.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/pages/PublicNotice/ApplyForm/PublicNoticeApplyForm.js b/src/pages/PublicNotice/ApplyForm/PublicNoticeApplyForm.js index 1a73e06..e4fd310 100644 --- a/src/pages/PublicNotice/ApplyForm/PublicNoticeApplyForm.js +++ b/src/pages/PublicNotice/ApplyForm/PublicNoticeApplyForm.js @@ -92,9 +92,19 @@ const PublicNoticeApplyForm = ({loadedData, selections}) => { }); const readFile=(event)=>{ - if(event.target.files[0]){ - if(event.target.files[0]) - setAttachment(event.target.files[0]); + let file = event.target.files[0]; + if(file){ + if(file.type == "application/vnd.openxmlformats-officedocument.wordprocessingml.documen" + || file.type == "application/msword" + || file.type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" + || file.type == "application/vnd.ms-excel" + ){ + setAttachment(event.target.files[0]); + }else{ + setWarningText("請上傳有效檔案 (檔案格式: .doc, .docx, .xls, .xlsx)"); + setIsWarningPopUp(true); + return; + } } } @@ -178,7 +188,7 @@ const PublicNoticeApplyForm = ({loadedData, selections}) => { id="uploadFileBtn" name="file" type="file" - accept=".doc,.docx,.xml,.xlsx" + accept=".doc,.docx,.xls,.xlsx" style={{ display: 'none' }} onChange={(event)=> { readFile(event)