Browse Source

Fix #1465: Correct content.length parsing issue in preview cache

Kartik Visweswaran 5 years ago
parent
commit
b5268e7622
3 changed files with 8 additions and 6 deletions
  1. 2 1
      CHANGE.md
  2. 6 5
      js/fileinput.js
  3. 0 0
      js/fileinput.min.js

+ 2 - 1
CHANGE.md

@@ -5,7 +5,8 @@ Change Log: `bootstrap-fileinput`
 
 **Date:** _under development_
 
-- (enh #1461): Allow two different max file count checks
+- (bug #1465): Correct content.length parsing issue in preview cache.
+- (enh #1461): Allow two different max file count checks.
     - `maxFileCount` and `msgFilesTooMany` for files being selected before upload
     - `maxTotalFileCount` and `msgTotalFilesTooMany` for total files selected and files included in initial preview
 - (enh #1448): New boolean properties `focusCaptionOnBrowse` and `focusCaptionOnClear` which default to `true`.

+ 6 - 5
js/fileinput.js

@@ -1762,10 +1762,11 @@
                     self.previewCache.data = data;
                 },
                 add: function (content, config, tags, append) {
-                    var data = self.previewCache.data, index = content.length - 1;
+                    var data = self.previewCache.data, index;
                     if (!content || !content.length) {
-                        return index;
+                        return 0;
                     }
+                    index = content.length - 1;
                     if (!$h.isArray(content)) {
                         content = content.split(self.initialPreviewDelimiter);
                     }
@@ -4592,8 +4593,8 @@
                         p2 = {id: previewId, index: index, file: file, files: files};
                     return isAjaxUpload ? self._showFileError(mesg, p1) : self._showError(mesg, p2);
                 },
-                maxCountCheck = function (n, m) {
-                    var msg = inclAll ? self.msgTotalFilesTooMany : self.msgFilesTooMany;
+                maxCountCheck = function (n, m, all) {
+                    var msg = all ? self.msgTotalFilesTooMany : self.msgFilesTooMany;
                     msg = msg.replace('{m}', m).replace('{n}', n);
                     self.isError = throwError(msg, null, null, null);
                     self.$captionContainer.removeClass('icon-visible');
@@ -4638,7 +4639,7 @@
                     total = self._getFileCount(initCount, true);
                     if (maxTotCount > 0 && total > maxTotCount) {
                         if (!self.autoReplace || len > maxCount) {
-                            maxCountCheck((self.autoReplace && len > maxTotCount ? len : total), maxTotCount);
+                            maxCountCheck((self.autoReplace && len > maxTotCount ? len : total), maxTotCount, true);
                             return;
                         }
                         if (total > maxCount) {

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