From 030f44f157311f40294b95b85188a802018db454 Mon Sep 17 00:00:00 2001 From: mertsincan Date: Wed, 1 Apr 2020 13:20:19 +0300 Subject: [PATCH] Fixed #254 - FileUpload in auto mode sends two post requests in IE11 --- src/components/fileupload/FileUpload.vue | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/components/fileupload/FileUpload.vue b/src/components/fileupload/FileUpload.vue index b6a030574..d1dc93358 100644 --- a/src/components/fileupload/FileUpload.vue +++ b/src/components/fileupload/FileUpload.vue @@ -98,6 +98,7 @@ export default { default: 'Cancel' } }, + duplicateIEEvent: false, data() { return { files: null, @@ -108,6 +109,11 @@ export default { }, methods: { onFileSelect(event) { + if (event.type !== 'drop' && this.isIE11() && this.duplicateIEEvent) { + this.duplicateIEEvent = false; + return; + } + this.messages = []; this.files = this.files || []; let files = event.dataTransfer ? event.dataTransfer.files : event.target.files; @@ -128,7 +134,10 @@ export default { this.upload(); } - if (this.isAdvanced) { + if (event.type !== 'drop' && this.isIE11()) { + this.clearIEInput(); + } + else { this.clearInputElement(); } }, @@ -213,6 +222,9 @@ export default { return false; }, + isIE11() { + return !!window['MSInputMethodContext'] && !!document['documentMode']; + }, validate(file) { if (this.maxFileSize && file.size > this.maxFileSize) { this.messages.push(this.invalidFileSizeMessage.replace('{0}', file.name).replace('{1}', this.formatSize(this.maxFileSize))); @@ -248,6 +260,12 @@ export default { clearInputElement() { this.$refs.fileInput.value = ''; }, + clearIEInput() { + if (this.$refs.fileInput) { + this.duplicateIEEvent = true; //IE11 fix to prevent onFileChange trigger again + this.$refs.fileInput.value = ''; + } + }, formatSize(bytes) { if (bytes === 0) { return '0 B';