I couldn't find a solution using the original Bootstrap entry, but I managed to achieve the desired result by implementing some clever tricks. Specifically, I changed the text of the file input form. Let me demonstrate how I accomplished this using the example you provided.
Here is the code for the input form taken from Bootstrap Docs:
<div class="mb-3">
<label for="formFile" class="form-label">Default file input example</label>
<input class="form-control" type="file" id="formFile">
</div>
The idea was to swap out the file input tag
with a text input tag
, and then use JavaScript to handle the actions associated with the file input form.
<!-- Using an online Bootstrap resource -->
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="26444949525552544756661308170815">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div class="mb-3">
<label for="file_input_id" class="form-label">Default file input example</label>
<!-- Using opacity and height styles to hide the file input form -->
<input class="form-control" type="file" id="file_input_id" style="opacity:0;height:0;">
<!-- Using another text input group to replace the file input form -->
<div class="input-group mb-3">
<span class="input-group-text" id="text_input_span_id">Any text here</span>
<!-- Setting 'caret-color: transparent' to hide the input cursor, turning autocomplete off to remove possible input hints -->
<input type="text" id='text_input_id' class="form-control" placeholder="Another text here" style="caret-color: transparent" autocomplete="off">
</div>
</div>
<!-- Using an online jQuery script -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
// Binding click action of file-input-form to text-input-span
$('#text_input_span_id').click(function () {
$("#file_input_id").trigger('click');
})
// Binding click action of file-input-form to text-input-form
$('#text_input_id').click(function () {
$("#file_input_id").trigger('click');
})
// Displaying filename in text-input-form
$("#file_input_id").change(function () {
$('#text_input_id').val(this.value.replace(/C:\\fakepath\\/i, ''))
})
</script>
Click on the input form, select a file, and see it in action!
https://i.stack.imgur.com/Teti8.png
If you wish to move the button to the right side, simply adjust the order of span and input tags accordingly.