最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Remove dropzone of thumbs and hide the div containing dropzone - Stack Overflow

programmeradmin1浏览0评论

I'm using the dropzone.js file uploader. Everything works fine but once I've uploaded I want to clear the dropzone of thumbs and hide the div containing dropzone. That's where things go awry. The thumbs still stay in place despite my efforts to clear them.

I've tried all the suggestions in the Dropzone.js site but nothing seems to work. I can get separate remove buttons to work using their example but can't have a master remove button. And yes, I've tried the FAQ example as well. I took the code straight from the tutorial and just added the references to the libraries and it still wouldn't remove the thumbs.

<!doctype html>
<html>
<head>
<link href="style/dropzone.css?v=1.2" type="text/css" rel="stylesheet" />
<script src="js/dropzone.min.js"></script>
<script language="javascript">
function ClearDZ() {
            myDropzone.removeAllFiles();
            document.getElementById("container").style.display = "none";
  }
</script>
<meta charset="UTF-8">
</head>

<body>
<div id=container>
<form id="myDropzone" action="/target-url" class="dropzone"></form>
<button onclick="ClearDZ()">Clear All</button>
<div>
</body>
</html>

I'm using the dropzone.js file uploader. Everything works fine but once I've uploaded I want to clear the dropzone of thumbs and hide the div containing dropzone. That's where things go awry. The thumbs still stay in place despite my efforts to clear them.

I've tried all the suggestions in the Dropzone.js site but nothing seems to work. I can get separate remove buttons to work using their example but can't have a master remove button. And yes, I've tried the FAQ example as well. I took the code straight from the tutorial and just added the references to the libraries and it still wouldn't remove the thumbs.

<!doctype html>
<html>
<head>
<link href="style/dropzone.css?v=1.2" type="text/css" rel="stylesheet" />
<script src="js/dropzone.min.js"></script>
<script language="javascript">
function ClearDZ() {
            myDropzone.removeAllFiles();
            document.getElementById("container").style.display = "none";
  }
</script>
<meta charset="UTF-8">
</head>

<body>
<div id=container>
<form id="myDropzone" action="/target-url" class="dropzone"></form>
<button onclick="ClearDZ()">Clear All</button>
<div>
</body>
</html>
Share Improve this question edited May 20, 2014 at 10:09 user3200528 asked May 19, 2014 at 18:32 user3200528user3200528 631 gold badge1 silver badge8 bronze badges 5
  • 1 And your problem is ? – Andrei Commented May 19, 2014 at 18:34
  • 1 What HAVE you tried so that we're not giving duplicate suggestions you've already tried. What DOES happen when you've tried each method? – Lee S Commented May 19, 2014 at 19:04
  • The thumbs stay visible in the dropzone form. They are supposed to be removed. When I set the display back to block, they are still there. – user3200528 Commented May 20, 2014 at 5:37
  • Actually, with the syntax as is, even the div isn't hidden. Obviously a problem at the removeAllFiles line. I have tried using the separate remove buttons in the FAQ which uses _this.removeFile(file); That works for one file at a time. I tried a variation _this.removeAllFiles(); That did exactly the same thing: Removed one file but not all. Everything else has done absolutely nothing. – user3200528 Commented May 20, 2014 at 5:43
  • Are you getting any errors in your console? – Andy Commented May 20, 2014 at 10:14
Add a ment  | 

2 Answers 2

Reset to default 6

I wonder where are your dropzone configuration and how did you configure it. If your code is as plain as you showed, you should configure your dropzone and listen to events. Try this:

<script>
//I'm assuming your form is called myDropzone
Dropzone.options.myDropzone = {
  //your configuration goes here

  init: function() {
    var myDropzone = this;

    //You can do this
    $('#your_button_id').on("click", function(e) {
      myDropzone.removeAllFiles(true);
    });

    //But you should do this
    this.on("success", function(file, response) {
      myDropzone.removeAllFiles(true);
    });

    //and this to handle any error
    this.on("error", function(file, response) {
      //handle errors here
    });
  }
}
</script>

You can have more information about listen to events at http://www.dropzonejs./#toc_8 and about configuration of Dropzone at http://www.dropzonejs./#toc_6

I hope you find it useful :)

try this on your library dropzone dropzone.js; but set time out to auto close 2500

success: function(file) {
    if (file.previewElement) {
      return file.previewElement.classList.add("dz-success"),
      $(function(){
        setTimeout(function(){
          $('.dz-success').fadeOut('slow');
        },2500);
      });
    }
  },
发布评论

评论列表(0)

  1. 暂无评论