Trigger fileupload form field change on file removal (#3319)

Credit to @jimcottrell
This commit is contained in:
Jim Cottrell 2017-12-22 14:33:21 -07:00 committed by Luke Towers
parent d54c3b18e9
commit 0d0be9d0e5

View File

@ -3,7 +3,7 @@
*
* Data attributes:
* - data-control="fileupload" - enables the file upload plugin
* - data-unique-id="XXX" - an optional identifier for multiple uploaders on the same page, this value will
* - data-unique-id="XXX" - an optional identifier for multiple uploaders on the same page, this value will
* appear in the postback variable called X_OCTOBER_FILEUPLOAD
* - data-template - a Dropzone.js template to use for each item
* - data-error-template - a popover template used to show an error
@ -85,7 +85,7 @@
this.$filesContainer = null
this.uploaderOptions = null
// In some cases options could contain callbacks,
// In some cases options could contain callbacks,
// so it's better to clean them up too.
this.options = null
@ -203,10 +203,7 @@
$img.attr('src', response.thumb)
}
/*
* Trigger change event (Compatability with october.form.js)
*/
this.$el.closest('[data-field-name]').trigger('change.oc.formwidget')
this.triggerChange();
}
FileUpload.prototype.onUploadError = function(file, error) {
@ -214,6 +211,13 @@
$preview.addClass('is-error')
}
/*
* Trigger change event (Compatibility with october.form.js)
*/
FileUpload.prototype.triggerChange = function() {
this.$el.closest('[data-field-name]').trigger('change.oc.formwidget')
}
FileUpload.prototype.addExtraFormData = function(formData) {
if (this.options.extraData) {
$.each(this.options.extraData, function (name, value) {
@ -307,6 +311,7 @@
.one('ajaxDone', function(){
self.removeFileFromElement($object)
self.evalIsPopulated()
self.triggerChange()
})
.request()