【问题标题】:Dropzone previews not displaying in preview zoneDropzone 预览未显示在预览区域中
【发布时间】:2016-04-22 08:58:38
【问题描述】:

我正在使用 Matias Meno 的教程将 dropzone 程序化地实现到表单中:https://github.com/enyo/dropzone/wiki/Combine-normal-form-with-Dropzone

预览无法正确显示在 preview-zone div 中,我不知道为什么。

HTML:

      <form id="my-awesome-dropzone" action="/uploads" class="dropzone">
            <fieldset name="contact-form-fieldset">
                <legend><h1>Request Services</h1></legend>
                <ul>
                    <li class="contact-form-fieldset-title">Full Name</li>
                    <li><input type="text" name="name" id="contact-form-name" class="plain buffer"></li>
                    <li class="contact-form-fieldset-title">
                    <li class="contact-form-fieldset-title">Email</li>
                    <li><input type="email" name="email" id="contact-form-email" class="plain buffer"></li>
                    <li class="contact-form-fieldset-title">Phone</li>
                    <li><input type="text" name="phone" id="contact-form-phone" class="plain buffer"></li>
                    <li class="contact-form-fieldset-title">Describe the problem with your device</li>
                    <li>
                        <textarea class="plain buffer" id="styled" name="styled-textarea"></textarea>
                    </li>
                    <li>
                          <div class="dropzone-previews"></div> <!-- this is were the previews should be shown. -->
                    </li>
                </ul>
                <div id="contact-form-fieldset-button">
                <button type="submit">Submit data and files!</button>
                </div>
            </fieldset>
            <p>In a hurry? Call 632-345-674</p>
        </form>
     <script src="../js/dropzone.js"></script>
     <script src="../js/uploader.js"></script>

uploader.js 文件包含 Matias 的原始代码:

Dropzone.options.myAwesomeDropzone = { // The camelized version of the ID of the form element

// The configuration we've talked about above
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 100,
maxFiles: 100,

  // The setting up of the dropzone
init: function() {
  var myDropzone = this;

// First change the button to actually tell Dropzone to process the queue.
this.element.querySelector("button[type=submit]").addEventListener("click", function(e) {
  // Make sure that the form isn't actually being sent.
  e.preventDefault();
  e.stopPropagation();
  myDropzone.processQueue();
});

// Listen to the sendingmultiple event. In this case, it's the sendingmultiple event instead
// of the sending event because uploadMultiple is set to true.
this.on("sendingmultiple", function() {
  // Gets triggered when the form is actually being sent.
  // Hide the success button or the complete form.
});
this.on("successmultiple", function(files, response) {
  // Gets triggered when the files have successfully been sent.
  // Redirect user or notify of success.
});
this.on("errormultiple", function(files, response) {
  // Gets triggered when there was an error sending the files.
  // Maybe show form again, and notify user of error
}); }}

有人有什么建议吗?

谢谢!

【问题讨论】:

  • 浏览器控制台是否显示任何错误?除了预览之外,文件上传功能是否正常工作?
  • @jkris,没有错误。文件上传功能半途而废。预览会显示为已上传并显示,但预览下方会显示勾号和“x”,而不是文件成功上传后显示的勾号。
  • @jkris 我玩了一下并修复了 dropzone-preview 显示不正确的问题,但现在拖放功能不起作用.....我明白了错误“未捕获的 TypeError:无法读取属性 'addEventListener' of null”

标签: javascript dropzone.js


【解决方案1】:

试试 previewsContainer: ".dropzone-previews"

【讨论】:

    猜你喜欢
    • 2016-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-29
    • 2021-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多