javascript - Why can't I register a dropzone.js callback in my "ready" function? -


i have spent few days working dropzone.js first time.

i have made following configuration make translation swedish , create callback (dropzonefinished) when drop :

$(function () {     if (currentculture == "sv-se") {         dropzone.options.dropzoneform = {             dictdefaultmessage: "släpp dokument här som ska laddas upp.",             dictfallbackmessage: "din webbläsare har inte stöd för att ladda upp dokument genom att dra och släppa.",             dictfallbacktext: "använd följande formulär för att ladda upp dokument på gammalt sätt.",             dictfiletoobig: "dokumentet är för stor ({{filesize}}mib). maximal dokumentstorlek: {{maxfilesize}}mib.",             dictinvalidfiletype: "du kan inte ladda upp dokument av denna typ.",             dictresponseerror: "servern svarar med felkod {{statuscode}}.",             dictcancelupload: "avbryt dokumentuppladdningen",             dictcanceluploadconfirmation: "Är du säker på att du vill avbryta denna dokumentuppladdning?",             dictremovefile: "ta bort dokument",             dictmaxfilesexceeded: "du kan inte ladda upp fler dokument.",             init: function () {                 this.on("complete", function(file) {                     if (this.getuploadingfiles().length === 0 && this.getqueuedfiles().length === 0) {                         dropzonefinished();                     }                 });             }         };     } else {         dropzone.options.dropzoneform = {             /* added period. */             dictdefaultmessage: "drop files here upload.",             init: function () {                 this.on("complete", function (file) {                     if (this.getuploadingfiles().length === 0 && this.getqueuedfiles().length === 0) {                         dropzonefinished();                     }                 });             }         };     }; }); 

however separate general culture configuration more specific callback logic. tried move registration of callback ready function:

    $(document).ready(function () {         $('#dropzoneform').on('complete', function (file) {             if ($('#dropzoneform').getuploadingfiles().length === 0 && $('#dropzoneform').getqueuedfiles().length === 0) {                 dropzonefinished();             }         });     }); 

but on complete not called. knows why? there other ways split different types of dropzone.options?

i had similar issue needed use "complete" logic. however, according http://www.w3schools.com/tags/ref_eventattributes.asp, there no event named "complete" or "oncomplete". , reason may event response somewhere. instance, mean element "complete"? in form case, there may submission of it, "onsubmit" event exists. however, form submitted, nothing told "complete" condition. thus, on element #dropzoneform (which may form or on page #dropzoneform id) can not attach "complete" event, since not defined.

but dropzone has complete event, because events can defined. so, instead of writing:

$('#dropzoneform').on('complete', function (file) {     if ($('#dropzoneform').getuploadingfiles().length === 0 && $('#dropzoneform').getqueuedfiles().length === 0) {         dropzonefinished();     } }); 

you may write:

dropzone.options.dropzoneform.init = function () {     this.on("complete", function () {         if (this.getuploadingfiles().length === 0 && this.getqueuedfiles().length === 0) {             dropzonefinished();         }     }); } 

in way same functionality previously. , solve problem.

finally, solution may issue. if want initialize dropzoneform more functionality this? in case should move code dropzone.js, , put after if-else statement. work, too.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -