Bre*_*ter 3 file-upload bootstrap-4 symfony4
使用 Symfony 4.2.5,我制作了一个带有 FileType 文件上传字段的表单,如上传文件中所述。我使用了在form_themes和bootstrap4 中描述的 Bootstrap 4 主题。
config/packages/twig.yaml 包含:
twig:
form_themes: ['bootstrap_4_horizontal_layout.html.twig']
Run Code Online (Sandbox Code Playgroud)
当我加载网页并选择要上传的文件时,文件类型字段显示空白文件名:

我发现这个问题记录在Symfony 问题 27477 中。
在使用 Symfony 的 Bootstrap 4 主题时,有没有办法让 Symfony 4 FileType 字段显示选定的文件名?
为了使表单文件输入字段显示选定的文件名,Bootstrap 4.3 文档建议使用 JavaScript 库bs-custom-file-input。
将此 JavaScript 添加到您的网页:
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2393 次 |
| 最近记录: |