Skip to content

Instantly share code, notes, and snippets.

@ogabrielguerra
Last active July 21, 2021 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ogabrielguerra/0d093e7d167440e466ec8584b7239402 to your computer and use it in GitHub Desktop.
Save ogabrielguerra/0d093e7d167440e466ec8584b7239402 to your computer and use it in GitHub Desktop.
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