I need to validate if filename contains comma. I added code into jqueryfileupload.js and it works.
Question:
Is there a way to do this without adding code into jqueryfileupload.js ?
// jquery\jqueryfileupload.js
processActions: {
validate: function(data, options) {
if (options.disabled) {
return data;
}
var dfd = $.Deferred(), settings = this.options, file = data.files[data.index], fileSize;
if (options.minFileSize || options.maxFileSize) {
fileSize = file.size;
}
if ($.type(options.maxNumberOfFiles) === "number" && (settings.getNumberOfFiles() || 0) + data.files.length > options.maxNumberOfFiles) {
file.error = settings.i18n("maxNumberOfFiles");
} else if (options.acceptFileTypes && !(options.acceptFileTypes.test(file.type) || options.acceptFileTypes.test(file.name))) {
file.error = settings.i18n("acceptFileTypes");
// ADDED BLOCK
} else if (file.name.indexOf(ew.MULTIPLE_UPLOAD_SEPARATOR) !== -1) {
file.error = 'filename contains comma';
// -----------
} else if (fileSize > options.maxFileSize) {
file.error = settings.i18n("maxFileSize");
} else if ($.type(fileSize) === "number" && fileSize < options.minFileSize) {
file.error = settings.i18n("minFileSize");
} else {
delete file.error;
}
if (file.error || data.files.error) {
data.files.error = true;
dfd.rejectWith(this, [ data ]);
} else {
dfd.resolveWith(this, [ data ]);
}
return dfd.promise();
}
}
I tried this but fail
// Client Script
$('#x_<fieldname>').on('fileuploadchange', function(e, data){
$.each(data.files, function (i, file) {
if (file.name.indexOf(ew.MULTIPLE_UPLOAD_SEPARATOR) !== -1) {
file.error = 'filename contains comma';
}
});
});