They don't seem to get along - if I keep the preview, then my validation generates an alert, but it doesn't prevent the user from uploading the file.
My footer code currently looks like this:
<script>/* PREVIEW CODE CURRENTLY COMMENTED OUT BECAUSE RESTRICTING FILE TYPE IS MORE IMPORTANT THAN PREVIEW ********************
document.getElementById("InsertRecordLogo").setAttribute("onchange","loadFile(event)");
var loadFile = function(event) {
var output = document.getElementById('output');
output.src = URL.createObjectURL(event.target.files[0]);
};
*************************** */</script><scripttype="text/javascript">var file = document.getElementById('InsertRecordLogo');var extensions =['jpg','jpeg','png','svg'];
file.addEventListener('change',function(e){var ext =this.value.match(/.([^.]+)$/)[1];
console.log(ext);if(!extensions.includes(ext)){
alert('Invalid file format. Please upload only image files of type jpg, jpeg, png or svg');this.value ='';}});</script>
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
Question
DaveS
Hello, Community,I'm trying to use these two community posts together:
They don't seem to get along - if I keep the preview, then my validation generates an alert, but it doesn't prevent the user from uploading the file.
My footer code currently looks like this:
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.