【问题标题】:Symfony 4 Form file upload field does not show selected filename with Bootstrap 4 themeSymfony 4 Form文件上传字段不显示带有Bootstrap 4主题的选定文件名
【发布时间】:2019-04-14 19:26:21
【问题描述】:

使用 Symfony 4.2.5,我制作了一个带有 FileType 文件上传字段的表单,如upload file 所述。我使用了 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 字段显示选定的文件名?

【问题讨论】:

    标签: file-upload bootstrap-4 symfony4


    【解决方案1】:

    要使表单文件输入字段显示所选文件名,Bootstrap 4.3 documentation 建议使用 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>
    

    【讨论】:

      猜你喜欢
      • 2020-03-31
      • 2019-12-27
      • 2020-11-10
      • 2018-07-14
      • 2019-02-11
      • 1970-01-01
      • 1970-01-01
      • 2019-01-10
      • 2019-04-16
      相关资源
      最近更新 更多