-
Notifications
You must be signed in to change notification settings - Fork 62
/
base-file-field.js
42 lines (36 loc) · 1.31 KB
/
base-file-field.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(function (global) {
const eZ = global.eZ = global.eZ || {};
const SELECTOR_FIELD_LABEL = '.ez-field-edit__label-wrapper .col-form-legend';
class BaseFileFieldValidator extends global.eZ.BaseFieldValidator {
/**
* Validates the input
*
* @method validateInput
* @param {Event} event
* @returns {Object}
*/
validateInput(event) {
const input = event.currentTarget;
const label = this.fieldContainer.querySelector(SELECTOR_FIELD_LABEL).innerHTML;
const result = { isError: false };
if (input.required && !input.files.length) {
result.errorMessage = global.eZ.errors.emptyField.replace('{fieldName}', label);
}
return result;
}
/**
* Displays an error message: file size exceeds maximum value
*
* @method showSizeError
*/
showSizeError() {
const label = this.fieldContainer.querySelector(SELECTOR_FIELD_LABEL).innerHTML;
const result = {
isError: true,
errorMessage: global.eZ.errors.invalidFileSize.replace('{fieldName}', label)
};
return result;
}
}
eZ.BaseFileFieldValidator = BaseFileFieldValidator;
})(window);