New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v4 Custom File Input Dynamic "Choose file..." ::after pseudo selector #20813
Comments
Related: #17269. |
I don't think we're going to go with adding JS for this to the core project. Would an example be appropriate, or do we open ourselves to still adding this to our maintenance load. |
I don't imagine the maintenance would be huge. What's more of an issue is that we mention the need for additional JavaScript but don't provide any.
|
We've done the thing where we recommend code snippets in our docs without making them official plugins. Should we go that route @bardiharborow, or should/could this be the start of some larger potential forms.js file? |
@niftylettuce - thank you so much for posting this example! I agree 100% this should be added as an example in the Bootstrap docs, but I think Lodash dependency should be removed (refactor as you suggested). I also think a "remove" button similar to Jasny Bootstrap's file input would be handy as well (as clicking the input, choosing nothing and then clicking Cancel is not as intuitive IMO). |
Guys, what happened to this? I see that there has not been a final decision to implement this in the core or in the documentation. |
De-prioritized so we can get the beta out. |
A temporary link here would help at least, but I suppose most folks might find their way here anyway. |
I've changed my mind on this one and would love to see this tackled somehow. I'm curious if we can perhaps start a general set of form JS utilities—custom file input, parent validation classes, etc. |
@mdo I published |
I thought this would be in Beta 4. Put the file name in I created a JS for some projects using BS4 but it can't handle multiple files... |
I really enjoyed this solution I look forward to your progress. I tried to implement something in Vanilla that observed the |
Got bitten by this today. It's very strange to me to support styling something into being dysfunctional. Out of the box, following the documentation, the input box:
When I implemented this I honestly didn't see the notice that said you need custom JS, and when I did a second pass and did notice it I pulled in the If this is being solved in the future, I would suggest in the meantime making the "custom JS" statement more specific and possibly a warning box to avoid this confusion. |
Hi, Here it is as a jQuery plugin with the following enhancements (link to the repo, MIT license, contributions welcome) :
And the styles as SCSS using BS4 variables :
|
Its probably late for this comment but i just realized there is no need to re-write the custom file upload even for v4-Alpha just update the .custom-file-label using some jquery
|
Just improved @Ocoolsanni 's snippet a bit, which will handle two more cases:
$(document).on('change', '.custom-file-input', function () {
let fileName = $(this).val().replace(/\\/g, '/').replace(/.*\//, '');
$(this).parent('.custom-file').find('.custom-file-label').text(fileName);
}); Again, thanks @Ocoolsanni for the idea and the base snippet! |
I thought I should share this, maybe we could make this into a JavaScript component that can be toggled. It's a super helpful little JavaScript snippet and CSS that lets you have custom file input boxes with the "Choose file..." and "Browse" buttons, but when the user changes the file input (selects a file) it will show the file name. It should be cross-browser compatible as well. I used lodash for the
_
, but it could be refactored with whatever @cvrebert and @mdo would use here - I just did this pretty quickly. Hope you don't mind the ES6 syntax.Example Screenshots:
Usage
The text was updated successfully, but these errors were encountered: