[IMP] survey_extra_fields: new params max_file_size and allowed_extensions for file question type
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m45s
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m45s
This commit is contained in:
@@ -108,6 +108,31 @@ odoo.define("survey_extra_fields.survey_form", function (require) {
|
||||
_t("This question requires an answer.");
|
||||
if (questionRequired && !(this.files && this.files.length > 0)) {
|
||||
errors[questionId] = constrErrorMsg;
|
||||
return;
|
||||
}
|
||||
if (this.files && this.files.length > 0) {
|
||||
var file = this.files[0];
|
||||
var maxSizeMB = parseInt($(this).data("maxFileSize"));
|
||||
if (maxSizeMB && file.size > maxSizeMB * 1024 * 1024) {
|
||||
errors[questionId] = _.str.sprintf(
|
||||
_t("The file exceeds the maximum allowed size of %s MB."),
|
||||
maxSizeMB
|
||||
);
|
||||
return;
|
||||
}
|
||||
var allowedExtensions = $(this).data("allowedExtensions");
|
||||
if (allowedExtensions) {
|
||||
var allowed = allowedExtensions.split(",").map(function (e) {
|
||||
return e.trim().toLowerCase();
|
||||
});
|
||||
var ext = "." + file.name.split(".").pop().toLowerCase();
|
||||
if (!allowed.includes(ext)) {
|
||||
errors[questionId] = _.str.sprintf(
|
||||
_t("This file type is not allowed. Accepted formats: %s."),
|
||||
allowedExtensions
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user