Skip to content

Commit

Permalink
IBX-2020: Fixed error message (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasOsti authored Apr 7, 2022
1 parent a313d6f commit f21297a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 55 deletions.
15 changes: 2 additions & 13 deletions src/bundle/Resources/public/js/scripts/fieldType/ezbinaryfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(function (global, doc, ibexa) {
const SELECTOR_FIELD = '.ibexa-field-edit--ezbinaryfile';
const SELECTOR_FILESIZE_NOTICE = '.ibexa-data-source__message--filesize';

class EzBinaryFilePreviewField extends ibexa.BasePreviewField {
/**
Expand All @@ -24,18 +23,8 @@
}
}

class EzBinaryFileFieldValidator extends ibexa.BaseFileFieldValidator {
validateFileSize(event) {
event.currentTarget.dispatchEvent(new CustomEvent('ibexa-invalid-file-size'));

return {
isError: false,
};
}
}

doc.querySelectorAll(SELECTOR_FIELD).forEach((fieldContainer) => {
const validator = new EzBinaryFileFieldValidator({
const validator = new ibexa.BaseFileFieldValidator({
classInvalid: 'is-invalid',
fieldContainer,
eventsMap: [
Expand All @@ -50,7 +39,7 @@
selector: `input[type="file"]`,
eventName: 'ibexa-invalid-file-size',
callback: 'showFileSizeError',
errorNodeSelectors: [SELECTOR_FILESIZE_NOTICE],
errorNodeSelectors: ['.ibexa-form-error'],
},
],
});
Expand Down
20 changes: 1 addition & 19 deletions src/bundle/Resources/public/js/scripts/fieldType/ezimage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(function (global, doc, ibexa, Translator) {
const SELECTOR_FIELD = '.ibexa-field-edit--ezimage';
const SELECTOR_INPUT_FILE = 'input[type="file"]';
const SELECTOR_FILESIZE_NOTICE = '.ibexa-data-source__message--filesize';
const SELECTOR_ALT_WRAPPER = '.ibexa-field-edit-preview__image-alt';
const SELECTOR_INPUT_ALT = '.ibexa-field-edit-preview__image-alt .ibexa-data-source__input';
const EVENT_CANCEL_ERROR = 'ibexa-cancel-errors';
Expand Down Expand Up @@ -72,23 +71,6 @@
}

class EzImageFieldValidator extends ibexa.BaseFileFieldValidator {
toggleInvalidState(isError, config, input) {
super.toggleInvalidState(isError, config, input);

const container = this.getFieldTypeContainer(input.closest(this.fieldSelector));
const method = !!container.querySelector(`.${this.classInvalid}`) ? 'add' : 'remove';

container.classList[method](this.classInvalid);
}

validateFileSize(event) {
event.currentTarget.dispatchEvent(new CustomEvent('ibexa-invalid-file-size'));

return {
isError: false,
};
}

/**
* Validates the alternative text input
*
Expand Down Expand Up @@ -138,7 +120,7 @@
selector: `${SELECTOR_INPUT_FILE}`,
eventName: 'ibexa-invalid-file-size',
callback: 'showFileSizeError',
errorNodeSelectors: [SELECTOR_FILESIZE_NOTICE],
errorNodeSelectors: ['.ibexa-form-error'],
},
{
isValueValidator: false,
Expand Down
15 changes: 2 additions & 13 deletions src/bundle/Resources/public/js/scripts/fieldType/ezimageasset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
const SELECTOR_FIELD = '.ibexa-field-edit--ezimageasset';
const SELECTOR_INPUT_FILE = 'input[type="file"]';
const SELECTOR_INPUT_DESTINATION_CONTENT_ID = '.ibexa-data-source__destination-content-id';
const SELECTOR_FILESIZE_NOTICE = '.ibexa-data-source__message--filesize';
const token = doc.querySelector('meta[name="CSRF-Token"]').content;
const { showErrorNotification } = ibexa.helpers.notification;
const { showSuccessNotification } = ibexa.helpers.notification;
Expand Down Expand Up @@ -227,18 +226,8 @@
}
}

class EzImageAssetFieldValidator extends ibexa.BaseFileFieldValidator {
validateFileSize(event) {
event.currentTarget.dispatchEvent(new CustomEvent('ibexa-invalid-file-size'));

return {
isError: false,
};
}
}

doc.querySelectorAll(SELECTOR_FIELD).forEach((fieldContainer) => {
const validator = new EzImageAssetFieldValidator({
const validator = new ibexa.BaseFileFieldValidator({
classInvalid: 'is-invalid',
fieldContainer,
eventsMap: [
Expand All @@ -253,7 +242,7 @@
selector: `${SELECTOR_INPUT_FILE}`,
eventName: 'ibexa-invalid-file-size',
callback: 'showFileSizeError',
errorNodeSelectors: [SELECTOR_FILESIZE_NOTICE],
errorNodeSelectors: ['.ibexa-form-error'],
},
],
});
Expand Down
11 changes: 1 addition & 10 deletions src/bundle/Resources/public/js/scripts/fieldType/ezmedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@
const SELECTOR_MEDIA_WRAPPER = '.ibexa-field-edit-preview__media-wrapper';
const SELECTOR_INPUT_FILE = 'input[type="file"]';
const CLASS_MEDIA_WRAPPER_LOADING = 'ibexa-field-edit-preview__media-wrapper--loading';
const SELECTOR_FILESIZE_NOTICE = '.ibexa-data-source__message--filesize';

class EzMediaValidator extends ibexa.BaseFileFieldValidator {
validateFileSize(event) {
event.currentTarget.dispatchEvent(new CustomEvent('ibexa-invalid-file-size'));

return {
isError: false,
};
}

/**
* Validates the dimensions inputs
*
Expand Down Expand Up @@ -146,7 +137,7 @@
selector: SELECTOR_INPUT_FILE,
eventName: 'ibexa-invalid-file-size',
callback: 'showFileSizeError',
errorNodeSelectors: [SELECTOR_FILESIZE_NOTICE],
errorNodeSelectors: ['.ibexa-field-edit--ezmedia .ibexa-form-error'],
},
{
selector: '.ibexa-field-edit-preview__dimensions .form-control',
Expand Down

0 comments on commit f21297a

Please sign in to comment.