Bootstrap 4's file browser lacks the file name display, showing only "Choose file...". To address this issue, I created a JavaScript solution. Are there any alternative methods to solve this problem?
HTML
<label class="file">
<input type="file" id="file1" >
<span class="file-custom" data-content="Choose file..."></span>
</label>
jQuery
$("input[type=file]").change(function(){
var fieldVal = $(this).val();
if (fieldVal != undefined || fieldVal != "") {
$(this).next(".file-custom").attr('data-content', fieldVal);
}
});
CSS
.file-custom:after {
content: attr(data-content);
}
The main tweak is adding the data-content attribute to the span element, which also simplifies language changes.
Explore Bootstrap's file browser here: