Last active
August 29, 2015 14:01
-
-
Save salsalabs/b5a9d553cb27d620386b to your computer and use it in GitHub Desktop.
This script makes sure that a Salsa upload page has both a file and a file name before the upload is submitted. An alert is displayed if the file is missing. If the file is missing and the name is empty, then the script uses the basename of the file as the name.
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
<!-- Add client-side validation and defaulting to any upload page. --> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
if (/upload_page_KEY=\d+/.test(window.location.href)) { | |
$('#upload_page').submit(function () { | |
var file = $('*[name=file]').val(); | |
if (file.length == 0 || file == 'No file selected.') { | |
alert('Please click the Browser button to choose a file before submitting this form.'); | |
return(false); | |
} | |
var name = $('*[name=name]').val(); | |
if (name.length == 0) { | |
name = file.split('/').reverse()[0]; | |
$('*[name=name]').val(name); | |
alert("We've suggested a filename for your file. Please confirm that the filename is okay, then click the \"Upload File\" button."); | |
return(false); | |
} | |
return(true); | |
}) | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment