如何将文本输入添加到 dropzone 上传 [英] How to add text input to dropzone upload

查看:20
本文介绍了如何将文本输入添加到 dropzone 上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许用户为每个拖入 Dropzone 的文件提交一个标题,该文件将被输入到文本输入中.但我不知道如何添加它.大家可以帮帮我吗?

I'd like to allow users to submit a title for each file that is dragged into Dropzone that will be inputted into a text input. But i don't know how to add it. Everyone can help me?

这是我的html代码代码

This is my html code code

  <form id="my-awesome-dropzone" class="dropzone">
  <div class="dropzone-previews"></div> <!-- this is were the previews should be shown. -->

  <!-- Now setup your input fields -->
  <input type="email" name="username" id="username" />
  <input type="password" name="password" id="password" />

  <button type="submit">Submit data and files!</button>
</form>

这是我的脚本代码

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

  // The configuration we've talked about above
  url: "upload.php",
  autoProcessQueue: false,
  uploadMultiple: true,
  parallelUploads: 100,
  maxFiles: 100,
  maxFilesize:10,//MB

  // 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
    });
  },
  accept: function (file, done) {
        //maybe do something here for showing a dialog or adding the fields to the preview?
    },
 addRemoveLinks: true
}
</script>  

推荐答案

您实际上可以为 Dropzone 提供一个模板来呈现图像预览以及任何额外的字段.在您的情况下,我建议您使用默认模板或制作您自己的模板,然后在此处添加输入字段:

You can actually provide a template for Dropzone to render the image preview as well as any extra fields. In your case, I would suggest taking the default template or making your own, and simply adding the input field there:

<div class="dz-preview dz-file-preview">
    <div class="dz-image"><img data-dz-thumbnail /></div>
    <div class="dz-details">
        <div class="dz-size"><span data-dz-size></span></div>
        <div class="dz-filename"><span data-dz-name></span></div>
    </div>
    <div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>
    <div class="dz-error-message"><span data-dz-errormessage></span></div>
    <input type="text" placeholder="Title">
</div>

完整的默认预览模板可以在dropzone.js的源代码中找到.

The full default preview template can be found in the source code of dropzone.js.

然后,您可以简单地将自定义模板作为选项参数的 previewTemplate 键的字符串传递给 Dropzone.例如:

Then you can simply pass your custom template to Dropzone as a string for the previewTemplate key of the option parameters. For example:

var myDropzone = new Dropzone('#yourId', {
    previewTemplate: "..."
});

只要你的元素是一个表单,Dropzone 就会自动在 xhr 请求参数中包含所有输入.

As long as your element is a form, Dropzone will automatically include all inputs in the xhr request parameters.

这篇关于如何将文本输入添加到 dropzone 上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆