I'm trying to prevent a file input being changed if I conditionally tell the user the file is too large, but even capturing the change and preventing default, it's still filled in ie:
// CHECK FILE ISNT ABOVE 500MB ON CHANGE
$(".upload-file").change(function (e) {
// conditional checks
var fileSize = $('.upload-file').get(0).files[0].size; // in bytes
if (fileSize > 500000000) {
e.preventDefault();
swal('File size is more than 500 MB, please upload a smaller file. Support for larger files will be rolled out soon.');
return false;
}
});
Here's my code, what am I doing wrong?
changeevent fires. You need to amend your logic to prevent the form firing asubmitevent if an invalid file is chosen.