首页 > 解决方案 > Bootstrap FileInput 在初始预览中填充输入值

问题描述

我正在使用 Krajee Bootstrap 文件输入。问题是,在我的编辑页面中,我想从记录中显示 PDF 文件的 initialPreview,但是当我提交表单进行更新时,文件输入发送空值。

这是我的代码:

形式 -

<div class="form-group col-md-4">
     <label for="pdf_file">Document</label>
        <div class="file-loading">
           <input class="file" name="pdf_file" id="pdf_file" value="" type="file">
        </div>
  </div>

JS——

$("#pdf_file").fileinput({
  theme: "fa",
  allowedFileExtensions: ["pdf"],
  maxFileCount: 1,
  showUpload: false,
  showCaption: false,
  overwriteInitial: true,
  fileType: "pdf",
  browseClass: "btn btn-primary btn-md",
  initialPreview: [                 
   "http://localhost/local_storage/aPxU3p71hpLjaI3lbTXrjRuigUxU94pq.pdf",
  ],
  initialPreviewAsData: true,
  initialPreviewConfig: [
    {type: "pdf", size: "100%", width: "100%", key: 1},
  ],
 });

提前致谢!!

标签: bootstrap-file-input

解决方案


检查文档以了解刷新方法。为此,您需要调用 destroy 方法,然后使用完整的新选项重新初始化插件。


推荐阅读