3

使用 Symfony 4.2.5,我制作了一个带有 FileType 文件上传字段的表单,如上传文件中所述。我使用了form_themesbootstrap4中描述的 Bootstrap 4 主题。

config/packages/twig.yaml 包含:

twig:
    form_themes: ['bootstrap_4_horizontal_layout.html.twig']

当我加载网页并选择要上传的文件时,FileType 字段显示一个空白文件名: 前

我发现这个问题记录在Symfony issue 27477中。

使用 Symfony 的 Bootstrap 4 主题时,有没有办法让 Symfony 4 FileType 字段显示选定的文件名?

4

1 回答 1

9

为了使表单文件输入字段显示选定的文件名,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>
于 2019-04-14T19:26:21.030 回答