|
|
@@ -2,7 +2,7 @@
|
|
|
* BootstrapValidator (http://bootstrapvalidator.com)
|
|
|
* The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
|
|
|
*
|
|
|
- * @version v0.5.3-dev, built on 2014-10-21 8:33:17 AM
|
|
|
+ * @version v0.5.3-dev, built on 2014-10-21 8:50:43 AM
|
|
|
* @author https://twitter.com/nghuuphuoc
|
|
|
* @copyright (c) 2013 - 2014 Nguyen Huu Phuoc
|
|
|
* @license MIT
|
|
|
@@ -3045,8 +3045,12 @@ if (typeof jQuery === 'undefined') {
|
|
|
$.fn.bootstrapValidator.validators.file = {
|
|
|
html5Attributes: {
|
|
|
extension: 'extension',
|
|
|
+ maxfiles: 'maxFiles',
|
|
|
+ minfiles: 'minFiles',
|
|
|
maxsize: 'maxSize',
|
|
|
minsize: 'minSize',
|
|
|
+ maxtotalsize: 'maxTotalSize',
|
|
|
+ mintotalsize: 'minTotalSize',
|
|
|
message: 'message',
|
|
|
type: 'type'
|
|
|
},
|
|
|
@@ -3058,8 +3062,12 @@ if (typeof jQuery === 'undefined') {
|
|
|
* @param {jQuery} $field Field element
|
|
|
* @param {Object} options Can consist of the following keys:
|
|
|
* - extension: The allowed extensions, separated by a comma
|
|
|
+ * - maxFiles: The maximum number of files
|
|
|
+ * - minFiles: The minimum number of files
|
|
|
* - maxSize: The maximum size in bytes
|
|
|
- * - minSize: the minimum size in bytes
|
|
|
+ * - minSize: The minimum size in bytes
|
|
|
+ * - maxTotalSize: The maximum size in bytes for all files
|
|
|
+ * - minTotalSize: The minimum size in bytes for all files
|
|
|
* - message: The invalid message
|
|
|
* - type: The allowed MIME type, separated by a comma
|
|
|
* @returns {Boolean}
|
|
|
@@ -3077,29 +3085,33 @@ if (typeof jQuery === 'undefined') {
|
|
|
|
|
|
if (html5) {
|
|
|
// Get FileList instance
|
|
|
- var files = $field.get(0).files,
|
|
|
- total = files.length;
|
|
|
+ var files = $field.get(0).files,
|
|
|
+ total = files.length,
|
|
|
+ totalSize = 0;
|
|
|
+
|
|
|
+ if ((options.maxFiles && total > parseInt(options.maxFiles, 10)) // Check the maxFiles
|
|
|
+ || (options.minFiles && total < parseInt(options.minFiles, 10))) // Check the minFiles
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
for (var i = 0; i < total; i++) {
|
|
|
- // Check the minSize
|
|
|
- if (options.minSize && files[i].size < parseInt(options.minSize, 10)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // Check the maxSize
|
|
|
- if (options.maxSize && files[i].size > parseInt(options.maxSize, 10)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ totalSize += files[i].size;
|
|
|
+ ext = files[i].name.substr(files[i].name.lastIndexOf('.') + 1);
|
|
|
|
|
|
- // Check file extension
|
|
|
- ext = files[i].name.substr(files[i].name.lastIndexOf('.') + 1);
|
|
|
- if (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) {
|
|
|
+ if ((options.minSize && files[i].size < parseInt(options.minSize, 10)) // Check the minSize
|
|
|
+ || (options.maxSize && files[i].size > parseInt(options.maxSize, 10)) // Check the maxSize
|
|
|
+ || (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) // Check file extension
|
|
|
+ || (files[i].type && types && $.inArray(files[i].type.toLowerCase(), types) === -1)) // Check file type
|
|
|
+ {
|
|
|
return false;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // Check file type
|
|
|
- if (files[i].type && types && $.inArray(files[i].type.toLowerCase(), types) === -1) {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ if ((options.maxTotalSize && totalSize > parseInt(options.maxTotalSize, 10)) // Check the maxTotalSize
|
|
|
+ || (options.minTotalSize && totalSize < parseInt(options.minTotalSize, 10))) // Check the minTotalSize
|
|
|
+ {
|
|
|
+ return false;
|
|
|
}
|
|
|
} else {
|
|
|
// Check file extension
|