perminder-klair / yii2-dropzone

DropzoneJs Extention for Yii2
51 stars 27 forks source link

AutoDiscover configuration ignored #15

Open xenogenesi opened 6 years ago

xenogenesi commented 6 years ago

I'm using Chromium (Chrome) and I've a couple of errors in the javascript console:

Uncaught Error: No URL provided.
Uncaught Error: Dropzone already attached.

registerJs() by default bind/wrap its code to the onready event (using jQuery) and this addon use it to configure the AutoDiscover option to true or false.

asset::register() doesn't bind/wrap to anything, as it should be for any javascript library/module, it is included at the end of the body after its dependencies and executed as soon as possible.

The problem is that DropZone, at least the version used by this addon, execute as soon as possible a contentLoaded function that seems to bind to the onload event, when the content is loaded the autoDiscover start.

So what is happening (at least on the Chromium I'm using) is that the DropZone's autoDiscover function is executed before the addon javascript set the autoDiscover configuration.

Currently the only solution I've found is to add a new asset, with the js code to disable the autoDiscover, add to it DropZoneAsset as dependency, and in DropZone.php register it instead, but is far from optimal.

gabriele-carbonai commented 6 years ago

I solved. Go to vendor/perminder-klair/dropzone/assets/DropZoneAssets.php change

public $js = [
        "dropzone/dist/min/dropzone.min.js"
    ];

to

public $js = [
        "dropzone/dist/dropzone.js"
    ];

now open dropzone.js and change Dropzone.autoDiscover = true; to Dropzone.autoDiscover = false;

tang05709 commented 6 years ago

感谢楼上大神的回答,解决了我的问题,另一种方式可以修改dropzone/dist/dropzone.js的Dropzone.autoDiscover = false, 然后使用压缩工具压缩并覆盖"dropzone/dist/min/dropzone.min.js"

mrstroz commented 5 years ago

Problem has been solved in my last pull request.

@perminder-klair Please check it and merge

xenogenesi commented 5 years ago

@mrstroz thanks, I can't test it right now but is looking good (much better/simple than my workaround). I'll give it a try as soon as I get some spare time

whizsid commented 5 years ago

@xenogenesi Can you merge this PR?

xenogenesi commented 5 years ago

@whizsid nope sorry, @perminder-klair should do it, but you can clone @mrstroz 's repository meanwhile