It seems that Bootstrap now tends to not add a JS solution for this, and instead will most likely include something like your script in the documentation as a suggested implementation based on mdo comments here, where there is also much more complete solution: https://github.com/twbs/bootstrap/issues/20813
I updated your simple code for Bootstrap 4 Alpha 6.
JQuery
$("input[type=file]").change(function () { var fieldVal = $(this).val(); if (fieldVal != undefined || fieldVal != "") { $(this).next(".custom-file-control").attr('data-content', fieldVal); } });
CSS
.custom-file-control:after { content: attr(data-content) !important; }
Edit:
In the above example, something like C:\\fakepath... will be shown, we can also get only the file name that will be shown using event.target.files[0].name :
$("input[type=file]").change(function (event) { var fieldVal = event.target.files[0].name; if (fieldVal != undefined || fieldVal != "") { $(this).next(".custom-file-control").attr('data-content', fieldVal); } });
Joey rizza
source share