Here we need to provide the same functionality for enter and space key. The raw HTML example above had some very helpful usability advantages: after selecting a special file I am able to see and read! To make this styled component a good alternative for the raw HTML version we should provide this as well.
I recommend setting the readonly attribute on the input, because the user should not be able to be entering stuff manually here, only by choosing a file to upload. To provide initial feedback I added a placeholder attribute that tells the user, that he has not chosen any files yet. This little jQuery example just picks the value of the fileupload element when it is changed, sets it as a value to our new filename element and wipes out some useless path information.
You can find the working example and the source code of it here. If you want to download the code, refer to my Github repository page. Learn more. Asked 4 years ago. Active 4 years ago. Viewed 11k times. Improve this question. Bhuwan I added the class "uploadButton" but its doesn't style the button itself.. Have you written the css for uploadButton class?
Add a comment. Active Oldest Votes. Improve this answer. Bhuwan Bhuwan I keep getting - File or directory not found. Try using the trigger method in jquery. Show 6 more comments. Jeremy Thille Wykk Wykk 5 5 silver badges 12 12 bronze badges. This is the simplest solution for me! Does anyone know how to change the. Now it just shows the same class. Anyone know how to track that? Thanks — Ando.
MehdiKaramosly it works even on IE 6 - but that is true only up to jQuery 1. JDawg JDawg 6, 2 2 gold badges 20 20 silver badges 27 27 bronze badges. Thanks for the heads up! The display: none approach breaks the native drag and drop support. You have missed code here. There is more on the fiddle. What library? There is just some javascript on the fiddle with jQuery to show files that has been dropped. That's all — kevcha. Having implemented this solution and tested it further, it doesn't seem to work either in Edge.
Ah ok, I missed the wrapper with position relative in your answer - My bad. If the input is below the screen dimensions, the browser tries to scroll to it and in doing so, moves the scroll container up the page. Here is a demonstration: stackblitz. Show 4 more comments.
Temani Afif k 16 16 gold badges silver badges bronze badges. Balvant Ahir Balvant Ahir 1 1 gold badge 7 7 silver badges 15 15 bronze badges. That's a lot better than the other solutions which do not display the name of selected file s. But how to change the text "Choose Files". So poorly done. I only add that firefox has it own similar class ::file-selector-button — Robert. JGuo JGuo 2 2 silver badges 7 7 bronze badges.
An alternative might be gist. Karthik Karthik 1, 15 15 silver badges 22 22 bronze badges. This approach gives you the whole flexibility! Satwik Nadkarny Satwik Nadkarny 4, 2 2 gold badges 21 21 silver badges 40 40 bronze badges. An ingeniously clever solution to this nefarious file upload styling shenanigans.
Put upload file button over your nice button or element and hide it. Tigran Babajanyan Tigran Babajanyan 1, 1 1 gold badge 17 17 silver badges 38 38 bronze badges. Setup some jquery to click the real input when you click the image. Just cut and paste the value when changed.
You may need to parse the val to something more meaningful but you should be all set. Good idea but this will not work on IE. So that attribute selector was added below. Note: These selectors blow up in IE so have to be separated from the same styles above.
Keep in mind IE gives you limited design control but at least you can customize its upload button. Stokely Stokely 6, 1 1 gold badge 22 22 silver badges 13 13 bronze badges. This is the real deal! Thanks a lot! Gianluca Ghettini Gianluca Ghettini 9, 15 15 gold badges 73 73 silver badges bronze badges. Also, click does work for any browsers and there is no veryfiable security reason as of now and on any devices it's the legit way and Gianluca for classic jQuery use trigger — Thielicious.
This is precisely the solution I was going to add to this! It work and you can display it precisely how you want to. Works with Chrome, will try others. JS without jQuery Array. ChrisRob ChrisRob 1, 1 1 gold badge 14 14 silver badges 27 27 bronze badges. Abdallah Okasha Abdallah Okasha 1, 15 15 silver badges 19 19 bronze badges. Caleb Caleb 4 4 silver badges 6 6 bronze badges.
How to solely display the file name, and not the fakepath path? Not sure why it's down voted. If you're using angular this is the simplest solution available. Maybe a lot of awnsers. But I like this in pure CSS with fa-buttons:. Johan Hoeksma Johan Hoeksma 3, 4 4 gold badges 24 24 silver badges 34 34 bronze badges.
To be exact, the label approach does work, except it can't show the selected file name or path. So necessarily speaking, that's the only issue one needs JS to solve. Warning: Everything below this is crap! Old Update Turned this into a Stylus mixin. D-Inventor D-Inventor 81 1 1 silver badge 1 1 bronze badge.
James Marquez James Marquez 3 3 silver badges 12 12 bronze badges. Despertaweb Despertaweb 1, 18 18 silver badges 27 27 bronze badges. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back
0コメント