Динамически меняйте максимальные файлы Dropzone - javascript
0
Я пытаюсь динамически обновлять свойство MaxFiles каждый раз, когда новое изображение загружается/удаляется. Используя следующий код, вы не разрешаете загружать любое изображение вместо того, чтобы ограничивать его до maxFiles. И это не принимает значение переменной maxFile
, но когда я удаляю переменную maxFile
и помещаю число, тогда она работает нормально. получил идею исходного кода из этого ответа.
!function ($) {
"use strict";
var Onyx = Onyx || {};
Onyx = {
init: function() {
var self = this,
obj;
for (obj in self) {
if ( self.hasOwnProperty(obj)) {
var _method = self[obj];
if ( _method.selector !== undefined && _method.init !== undefined ) {
if ( $(_method.selector).length > 0 ) {
_method.init();
}
}
}
}
},
userFilesDropzone: {
selector: form.dropzone,
init: function() {
var base = this,
container = $(base.selector);
base.initFileUploader(base, form.dropzone);
},
initFileUploader: function(base, target) {
var maxFile = $(.dropzone).attr(data-count);
var onyxDropzone = new Dropzone(target, {
url: ($(target).attr("action")) ? $(target).attr("action") : "data.php", // Check that our form has an action attr and if not, set one here
maxFiles: maxFile,
maxFilesize: 5,
acceptedFiles: ".JPG,.PNG,.JPEG",
// previewTemplate: previewTemplate,
// previewsContainer: "#previews",
clickable: true,
uploadMultiple: false,
});
onyxDropzone.on("success", function(file, response) {
let parsedResponse = JSON.parse(response);
file.upload_ticket = parsedResponse.file_link;
var imagecount = $(.dropzone).attr(data-count);
imagecount = imagecount - 1;
$(.dropzone).attr(data-count, imagecount);
});
},
}
}
}// JavaScript Document
function openImagePopup(id = null) {
$(".upload-images").show();
$.ajax({
url: fetch.php,
type: post,
data: {id: id},
dataType: json,
success:function(response) {
var imagecount = response.counts;
$(.dropzone).attr(data-count, imagecount);
}
});
}
Источник
- 184
- 0
- 11 май 2020 2020-05-11 10:17:37
- lipon
Ответов пока нет