Symfony 4表单文件上传字段不显示具有Bootstrap 4主题的所选文件名 [英] Symfony 4 Form file upload field does not show selected filename with Bootstrap 4 theme
问题描述
使用Symfony 4.2.5,我创建了一个带有FileType文件上传字段的表单,如 form_themes 和
Using Symfony 4.2.5, I made a Form with a FileType file upload field as described at upload file. I used the Bootstrap 4 theme as described at form_themes and bootstrap4.
config/packages/twig.yaml包含:
config/packages/twig.yaml contains:
twig:
form_themes: ['bootstrap_4_horizontal_layout.html.twig']
当我加载网页并选择要上传的文件时,文件类型"字段显示空白文件名:
When I load the web page and select a file to upload, the FileType field shows a blank filename:
我发现此问题记录在 Symfony问题27477 中.
I found this issue was documented in Symfony issue 27477.
使用Symfony的Bootstrap 4主题时,是否可以使Symfony 4 FileType字段显示选定的文件名?
Is there a way to make the Symfony 4 FileType field show the selected filename when using Symfony's Bootstrap 4 theme?
推荐答案
要使表单文件"输入字段显示所选文件名,请 bs-custom-file-input .
To make the Form file input field show the selected filename, Bootstrap 4.3 documentation recommends using the JavaScript library bs-custom-file-input.
将此JavaScript添加到您的网页:
Add this JavaScript to your web page:
<script src="https://cdn.jsdelivr.net/npm/bs-custom-file-input/dist/bs-custom-file-input.min.js"></script>
<script>
$(document).ready(function () {
bsCustomFileInput.init()
})
</script>
这篇关于Symfony 4表单文件上传字段不显示具有Bootstrap 4主题的所选文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!