Bladeren bron

Fix #295: Validate `overwriteInitial` correctly for ajax uploads

Kartik Visweswaran 10 jaren geleden
bovenliggende
commit
374584581c
3 gewijzigde bestanden met toevoegingen van 19 en 13 verwijderingen
  1. 3 2
      CHANGE.md
  2. 16 11
      js/fileinput.js
  3. 0 0
      js/fileinput.min.js

+ 3 - 2
CHANGE.md

@@ -4,8 +4,9 @@ version 4.2.1
 
 1. (enh #279, #280): Fixed error for failed response types.
 2. (enh #287): Add Brazilian Portugese (pt-BR) translations.
-3. (enh #296): Fixed license identifiers in bower.json and composer.json.
-4. (enh #297): Add Romanian translations.
+3. (bug #295): Validate `overwriteInitial` correctly for ajax uploads.
+4. (enh #296): Fixed license identifiers in bower.json and composer.json.
+5. (enh #297): Add Romanian translations.
 
 version 4.2.0
 =============

+ 16 - 11
js/fileinput.js

@@ -524,7 +524,7 @@
             var self = this, errMsg = $.trim(errorThrown + ''),
                 dot = errMsg.slice(-1) === '.' ? '' : '.',
                 text = jqXHR.responseJSON !== undefined && jqXHR.responseJSON.error !== undefined
-                        ? jqXHR.responseJSON.error : jqXHR.responseText;
+                    ? jqXHR.responseJSON.error : jqXHR.responseText;
             if (self.showAjaxErrorDetails) {
                 text = $.trim(text.replace(/\n\s*\n/g, '\n'));
                 text = text.length > 0 ? '<pre>' + text + '</pre>' : '';
@@ -1879,6 +1879,16 @@
                 return;
             }
             self.resetErrors();
+            total = self.isUploadable ? self.getFileStack().length + tfiles.length : tfiles.length;
+            if (self.maxFileCount > 0 && total > self.maxFileCount) {
+                msg = self.msgFilesTooMany.repl('{m}', self.maxFileCount).repl('{n}', total);
+                self.isError = throwError(msg, null, null, null);
+                self.$captionContainer.find('.kv-caption-icon').hide();
+                self.$caption.html(self.msgValidationError);
+                self.setEllipsis();
+                self.$container.removeClass('file-input-new file-input-ajax-new');
+                return;
+            }
             if (!isAjaxUpload || (isSingleUpload && ctr > 0)) {
                 if (!self.overwriteInitial && previewCache.count(self.id)) {
                     var out = previewCache.out(self.id);
@@ -1892,16 +1902,11 @@
                 if (isSingleUpload && ctr > 0) {
                     self.filestack = [];
                 }
-            }
-            total = self.isUploadable ? self.getFileStack().length + tfiles.length : tfiles.length;
-            if (self.maxFileCount > 0 && total > self.maxFileCount) {
-                msg = self.msgFilesTooMany.repl('{m}', self.maxFileCount).repl('{n}', total);
-                self.isError = throwError(msg, null, null, null);
-                self.$captionContainer.find('.kv-caption-icon').hide();
-                self.$caption.html(self.msgValidationError);
-                self.setEllipsis();
-                self.$container.removeClass('file-input-new file-input-ajax-new');
-                return;
+            } else {
+                if (isAjaxUpload && self.overwriteInitial) {
+                    $preview.html('');
+                    self.filestack = [];
+                }
             }
             if (!self.isIE9) {
                 self.readFiles(tfiles);

File diff suppressed because it is too large
+ 0 - 0
js/fileinput.min.js


Some files were not shown because too many files changed in this diff