Commit a92f9b38 authored by Primsi's avatar Primsi
Browse files

by primsi: refactor submit disabling.

parent 399967dd
......@@ -15,3 +15,9 @@ integration:
version: VERSION
js:
js/dropzone.integration.js: {}
dependencies:
- core/jquery
- core/drupal
- core/drupalSettings
- core/underscore
- dropzonejs/dropzonejs
......@@ -27,7 +27,7 @@
var dropzoneInstance = new Dropzone("#" + selector.attr("id"), $.extend({}, instanceConfig, config));
// Other modules might need instances.
Drupal.dropzonejsInstances.push(dropzoneInstance);
drupalSettings["dropzonejs"]["instances"][selector.attr("id")]["instance"] = dropzoneInstance;
// React on add file. Add only accepted files.
dropzoneInstance.on("success", function(file, response) {
......
......@@ -8,31 +8,30 @@
Drupal.behaviors.dropzonejsEbWidgetCommon = {
attach: function(context) {
if (Drupal.dropzonejsInstances.length) {
for (var i = 0; i < Drupal.dropzonejsInstances.length; i++) {
var instance = Drupal.dropzonejsInstances[i];
var $form = $(Drupal.dropzonejsInstances[i].element).parents('form');
if (typeof drupalSettings.dropzonejs.instances !== "undefined") {
_.each(drupalSettings.dropzonejs.instances, function (item) {
var $form = $(item.instance.element).parents('form');
if (form.hasClass('dropzonejs-disable-submit')) {
var $submit = form.find('input.form-submit');
submit.attr("disabled", "true");
if ($form.hasClass("dropzonejs-disable-submit")) {
var $submit = $form.find('[type=submit]');
$submit.prop("disabled", true);
instance.on("queuecomplete", function () {
if (instance.getRejectedFiles().length == 0) {
submit.removeAttr("disabled");
item.instance.on("queuecomplete", function () {
if (item.instance.getRejectedFiles().length == 0) {
$submit.prop("disabled", false);
}
else {
submit.attr("disabled", "true");
$submit.prop("disabled", true);
}
});
instance.on("removedfile", function (file) {
if (instance.getRejectedFiles().length == 0) {
submit.removeAttr("disabled");
item.instance.on("removedfile", function (file) {
if (item.instance.getRejectedFiles().length == 0) {
$submit.removeAttr("disabled");
}
});
}
}
});
}
}
};
......
......@@ -57,7 +57,7 @@ class DropzoneJs extends FormElement {
'#theme_wrappers' => ['form_element'],
'#tree' => TRUE,
'#attached' => [
'library' => ['dropzonejs/dropzonejs', 'dropzonejs/integration']
'library' => ['dropzonejs/integration']
],
];
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment