Skip to content

Commit 1ec4dee

Browse files
Illirgwaykartik-v
authored andcommitted
Correct isEmpty check for functions (#1496)
* BUGFIX: $h.isEmpty treat value = function() with zero args, as empty due to value.length === 0 => https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Function/length isEmpty should check is the value of type "function" before check its length. ex: ``` ... uploadUrl: function() { return ajax_url + '/upload/' + $el.data('id'); } ... ``` ```self.isAjaxUpload = $h.hasFileUploadSupport() && !$h.isEmpty(self.uploadUrl); // => false, but must be true``` * Update fileinput.js * Update fileinput.min.js
1 parent 0b7a84f commit 1ec4dee

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

js/fileinput.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,12 @@
211211
$modal.appendTo($body);
212212
}
213213
},
214+
// https://stackoverflow.com/a/6000016
215+
isFunction: function (v) {
216+
return !!(v && v.constructor && v.call && v.apply);
217+
},
214218
isEmpty: function (value, trim) {
215-
return value === undefined || value === null || value.length === 0 || (trim && $.trim(value) === '');
219+
return value === undefined || value === null || (!$h.isFunction(value) && ( value.length === 0 || (trim && $.trim(value) === '')));
216220
},
217221
isArray: function (a) {
218222
return Array.isArray(a) || Object.prototype.toString.call(a) === '[object Array]';
@@ -5658,4 +5662,4 @@
56585662
$input.fileinput();
56595663
}
56605664
});
5661-
}));
5665+
}));

0 commit comments

Comments
 (0)