Last active
July 21, 2021 22:42
-
-
Save ogabrielguerra/0d093e7d167440e466ec8584b7239402 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const handleResumeForm = (inputTargetId)=>{ | |
const RESUME_INPUT = document.getElementById(inputTargetId); | |
const RESUME_FILE_NAME = RESUME_INPUT.value; | |
const ALLOWED_EXTENSIONS = ['pdf','doc','docx']; | |
const ERROR_CLASS = 'form-error'; | |
const inArray = (array, key)=>{ | |
let result = false; | |
array.forEach((item)=>{ item === key ? result = true : '' }) | |
return result; | |
} | |
const throwError = ()=>{ | |
RESUME_INPUT.classList.add(ERROR_CLASS); | |
return false; | |
} | |
const proceed = ()=>{ | |
console.log('SENDING MESSAGE...'); | |
RESUME_INPUT.classList.remove(ERROR_CLASS); | |
new SendAMessage('<?=$actionUrl;?>', '<?=$idiom;?>'); | |
} | |
if (RESUME_FILE_NAME==='') return throwError(); | |
if (RESUME_FILE_NAME.indexOf('.')!==-1) { | |
let extension = RESUME_FILE_NAME.split('.').slice(-1)[0]; | |
!inArray(ALLOWED_EXTENSIONS, extension) ? throwError() : proceed(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment