javascript - Initialize dropzone after loading the form -


i'm using jquery dropzone.js. load form i'm using mustache below. can't innit dropzone after page loaded because there no form loaded on moment. there option init dropzone after it's loaded?

mustache file form:

<div class="col-lg-12">     <div class="ibox float-e-margins">         <div class="ibox-title">             <h5>dropzone area</h5>             <div class="ibox-tools">                 <a class="collapse-link">                     <i class="fa fa-chevron-up"></i>                 </a>                 <a class="dropdown-toggle" data-toggle="dropdown" href="#">                     <i class="fa fa-wrench"></i>                 </a>                 <ul class="dropdown-menu dropdown-user">                     <li><a href="#">config option 1</a>                     </li>                     <li><a href="#">config option 2</a>                     </li>                 </ul>                 <a class="close-link">                     <i class="fa fa-times"></i>                 </a>             </div>         </div>         <div class="ibox-content">             <form id="my-awesome-dropzone" class="dropzone" action="#">                 <div class="dropzone-previews"></div>                 <button type="submit" class="btn btn-primary pull-right">submit form!</button>             </form>             <div>                 <div class="m text-right"><small>dropzonejs open source library provides drag'n'drop file uploads image previews: <a href="https://github.com/enyo/dropzone" target="_blank">https://github.com/enyo/dropzone</a></small> </div>             </div>         </div>     </div> </div> 

the functions load mustache , init dropzone:

<script>     $( document ).ready(function() {         // mustache         loaddropzone();          // how can after dropzone form created?         // init dropzone         dropzone.options.myawesomedropzone = {              autoprocessqueue: false,             uploadmultiple: true,             paralleluploads: 100,             maxfiles: 100,              // dropzone settings             init: function () {                 var mydropzone = this;                  this.element.queryselector("button[type=submit]").addeventlistener("click", function (e) {                     e.preventdefault();                     e.stoppropagation();                     mydropzone.processqueue();                 });                 this.on("sendingmultiple", function () {                 });                 this.on("successmultiple", function (files, response) {                 });                 this.on("errormultiple", function (files, response) {                 });             }          }      });      function loaddropzone() {         $.get(websiteurl + 'storages/mustache/image-drop-zone.mst', function(template) {             mustache.parse(template); // speeds future uses             var rendered = mustache.render(template);             $('#block-container').append(rendered);         });     } </script> 

you should initialize dropzone programatically instead of using options , auto discover feature.

should this:

<script>     dropzone.autodiscover = false; // optional in case      $( document ).ready(function() {         // mustache         loaddropzone();          // form loaded can initialize dropzone creating instance         // init dropzone         var myawesomedropzone = new dropzone("form#my-awesome-dropzone", {              autoprocessqueue: false,             uploadmultiple: true,             paralleluploads: 100,             maxfiles: 100,              // dropzone settings             init: function () {                 var mydropzone = this;                  this.element.queryselector("button[type=submit]").addeventlistener("click", function (e) {                     e.preventdefault();                     e.stoppropagation();                     mydropzone.processqueue();                 });                 this.on("sendingmultiple", function () {                 });                 this.on("successmultiple", function (files, response) {                 });                 this.on("errormultiple", function (files, response) {                 });             }          }      });      function loaddropzone() {         $.get(websiteurl + 'storages/mustache/image-drop-zone.mst', function(template) {             mustache.parse(template); // speeds future uses             var rendered = mustache.render(template);             $('#block-container').append(rendered);         });     } </script> 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -