选择文件后如何禁用Dropzone.js?
How to disable Dropzone.js after choosing file?
在我的dropzone中我首先选择要保存的文件,然后点击保存按钮保存它。所以,我的问题是:如何在选择文件后禁用 dropzone 区域?我试过这样
accept: function (file, done) {
if (file.type != "image/jpeg" && file.type != "image/png" && file.type != "image/gif") {
$('.file-row').find('img').attr('src', '/../Content/images/decline.png');
$('.file-row').find('img').attr('class', 'error-img');
done("Error! Files of this type are not accepted");
}
else {
$('.file-row').find('img').attr('src', '/../Content/images/accept.png');
$('.file-row').find('img').attr('class', 'accept-img');
done();
logoDropzone.disable();
}
}
但是此代码不允许我上传文件,"Upload canceled" 弹出错误。我能做什么?
最好使用标准 dropzone.js 事件。它们被记录在案 here。
您可以简单地隐藏和显示输入
logoDropzone.on("addedfile", function (file) {
$('.dz-input').hide();
})
logoDropzone.on("deletedfile", function (file) {
$('.dz-input').show();
})
myDropzone.on('maxfilesreached', function() {
myDropzone.removeEventListeners();
});
myDropzone.on('removedfile', function (file) {
myDropzone.setupEventListeners();
});
如果您有来自服务器的文件,请不要忘记 init _updateMaxFilesReachedClass。
myDropzone._updateMaxFilesReachedClass()
您可以使用:
this.element.style.cursor = "not-allowed";
this.hiddenFileInput.style.cursor = "not-allowed";
this.hiddenFileInput.disabled = true;
按照你想要的逻辑使用它,它会在视觉上和功能上禁用 dropzone。
不是:这里的“this”指的是 dropzone 元素本身
在我的dropzone中我首先选择要保存的文件,然后点击保存按钮保存它。所以,我的问题是:如何在选择文件后禁用 dropzone 区域?我试过这样
accept: function (file, done) {
if (file.type != "image/jpeg" && file.type != "image/png" && file.type != "image/gif") {
$('.file-row').find('img').attr('src', '/../Content/images/decline.png');
$('.file-row').find('img').attr('class', 'error-img');
done("Error! Files of this type are not accepted");
}
else {
$('.file-row').find('img').attr('src', '/../Content/images/accept.png');
$('.file-row').find('img').attr('class', 'accept-img');
done();
logoDropzone.disable();
}
}
但是此代码不允许我上传文件,"Upload canceled" 弹出错误。我能做什么?
最好使用标准 dropzone.js 事件。它们被记录在案 here。 您可以简单地隐藏和显示输入
logoDropzone.on("addedfile", function (file) {
$('.dz-input').hide();
})
logoDropzone.on("deletedfile", function (file) {
$('.dz-input').show();
})
myDropzone.on('maxfilesreached', function() {
myDropzone.removeEventListeners();
});
myDropzone.on('removedfile', function (file) {
myDropzone.setupEventListeners();
});
如果您有来自服务器的文件,请不要忘记 init _updateMaxFilesReachedClass。
myDropzone._updateMaxFilesReachedClass()
您可以使用:
this.element.style.cursor = "not-allowed";
this.hiddenFileInput.style.cursor = "not-allowed";
this.hiddenFileInput.disabled = true;
按照你想要的逻辑使用它,它会在视觉上和功能上禁用 dropzone。
不是:这里的“this”指的是 dropzone 元素本身