Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

EZP-31743: Multi-input single field validation doesn't show proper error #1435

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bundle/Resources/encore/ez.js.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ module.exports = (Encore) => {
path.resolve(__dirname, '../public/js/scripts/fieldType/base/base-field.js'),
path.resolve(__dirname, '../public/js/scripts/fieldType/base/base-file-field.js'),
path.resolve(__dirname, '../public/js/scripts/fieldType/base/base-preview-field.js'),
path.resolve(__dirname, '../public/js/scripts/fieldType/base/multi-input-field.js'),
...fieldTypes,
path.resolve(__dirname, '../public/js/scripts/sidebar/extra.actions.js'),
])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(function(global, doc, eZ) {
class MultiInputFieldValidator extends eZ.BaseFieldValidator {
constructor({ containerSelectors, ...restProps }) {
super(restProps);

this.containerSelectors = containerSelectors;
}

toggleInvalidState(isError, config, input) {
super.toggleInvalidState(isError, config, input);

this.containerSelectors.forEach((selector) => {
const invalidSelector = `.${this.classInvalid}`;
const container = input.closest(selector);
const method = !!container.querySelector(invalidSelector) ? 'add' : 'remove';

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

eZ.addConfig('MultiInputFieldValidator', MultiInputFieldValidator);
})(window, window.document, window.eZ);
3 changes: 2 additions & 1 deletion src/bundle/Resources/public/js/scripts/fieldType/ezauthor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const SELECTOR_FIELD_EMAIL = '.ez-data-source__field--email';
const SELECTOR_FIELD_NAME = '.ez-data-source__field--name';

class EzAuthorValidator extends global.eZ.BaseFieldValidator {
class EzAuthorValidator extends global.eZ.MultiInputFieldValidator {
/**
* Validates the 'name' input field value
*
Expand Down Expand Up @@ -182,6 +182,7 @@
const validator = new EzAuthorValidator({
classInvalid: 'is-invalid',
fieldSelector: SELECTOR_FIELD,
containerSelectors: ['.ez-data-source__author', '.ez-field-edit--ezauthor'],
eventsMap: [
{
selector: `.ez-data-source__author ${SELECTOR_FIELD_NAME} .ez-data-source__input`,
Expand Down