question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom file input does not show file name after upload

See original GitHub issue

Hi,

I am using the .custom-file-input class to customize the <input type='file'>. It works as expected. I see that it is overlapping the default input element.

Issue: Typically the filename is displayed once we upload file. But here the label text is displayed even after uploading the file, i.e., Choose file should change to the uploaded filename.

Solution: I am able to see the file name if I change opacity:0 to opacity:1 from .custom-file-input class. We should be able to fetch the name of the file and replace the label name with the file name.

Below is the code I used:

<div class="custom-file">
  <input type="file" class="custom-file-input" id="customFile">
  <label class="custom-file-label" for="customFile">Choose file</label>
</div>

OS: Windows 10 and Android Oreo(8.1) Browser: Chrome Version 69.0.3497.100

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Johann-Scommented, Oct 3, 2018

Hi @arun-awnics

It’s written here: https://getbootstrap.com/docs/4.1/components/forms/#file-browser our custom file input need a bit of JavaScript to work.

Bootstrap recommend this plugin: https://github.com/Johann-S/bs-custom-file-input

1reaction
shubhamindrawatcommented, Jun 27, 2020

Hi @imayushshrivastava ,

You can use the below code which will definitely work for you:

$('#customFile').on('change', function(){ files = $(this)[0].files; name = ''; for(var i = 0; i < files.length; i++){ name += '\"' + files[i].name + '\"' + (i != files.length-1 ? ", " : ""); } $(".custom-file-label").html(name); });

Read more comments on GitHub >

github_iconTop Results From Across the Web

bootstrap 4 file input doesn't show the file name - Stack Overflow
I have a problem with the custom-file-input class in Bootstrap 4. after I chose which file I want to upload the filename do...
Read more >
Display file name in page after selecting file in file input
Insecure Resource. The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https....
Read more >
<input type="file"> - HTML: HyperText Markup Language | MDN
When a file is chosen using an <input type="file"> , the real path to the source file is not shown in the input's...
Read more >
How to customise a file upload control - Hidde's blog
To make a custom file upload control, use a standard file upload and label, then visually hide the input and style the label....
Read more >
How to get file input by selected file name without path using ...
After that we will get the file name by using the jQuery change() method. This method is used in the JQuery to get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found