Last active
January 31, 2019 19:35
-
-
Save VermillionOne/b525cf264bbbcaae8941ae5b5d04cb9e to your computer and use it in GitHub Desktop.
Display filename for custom file upload button
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
//For updating displayed file name for form file upload inputs - Requires jQuery | |
$('input[type="file"]').on('change', function(e) { | |
var fileSelect = e.target, | |
fileName = e.target.value.split(/\\|\//).pop(), | |
fileNameTruncated = fileName.length > 20 ? fileName.substr(0, 20) : fileName, | |
fileNameDisplay = fileSelect.dataset.displayfilename; | |
$("."+fileNameDisplay).html(fileNameTruncated+"..."+fileName.substr(fileName.length - 4)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment