-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Dariusz Szut <[email protected]> Co-authored-by: katarzynazawada <>
- Loading branch information
1 parent
9d8cd93
commit f6b11f7
Showing
19 changed files
with
644 additions
and
458 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/bundle/Resources/public/js/scripts/admin.form.tabs.validation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
(function (global, doc) { | ||
const tabsHeaders = doc.querySelectorAll('.ibexa-tabs[data-form-selector]'); | ||
const getHrefFromGroup = (group) => { | ||
if (group.dataset.id) { | ||
return group.dataset.id; | ||
} | ||
|
||
return `#${group.id}`; | ||
}; | ||
|
||
tabsHeaders.forEach((tabsHeader) => { | ||
const popupMenu = tabsHeader.querySelector('.ibexa-tabs__popup-menu'); | ||
const moreBtn = tabsHeader.querySelector('.ibexa-tabs__tab--more'); | ||
const { formSelector, formTabGroupSelector } = tabsHeader.dataset; | ||
const formNode = doc.querySelector(formSelector); | ||
const classInvalidChangedCallback = (mutationList) => { | ||
mutationList.forEach((mutation) => { | ||
const { oldValue, target } = mutation; | ||
const hadIsInvalidClass = oldValue?.includes('is-invalid') ?? false; | ||
const hasIsInvalidClass = target.classList.contains('is-invalid'); | ||
|
||
if (hadIsInvalidClass !== hasIsInvalidClass) { | ||
const sectionGroup = target.closest(formTabGroupSelector); | ||
|
||
if (!sectionGroup) { | ||
return; | ||
} | ||
|
||
const href = getHrefFromGroup(sectionGroup); | ||
const hasGroupError = !!sectionGroup.querySelector('.is-invalid'); | ||
const correspondingMenuItemLink = doc.querySelector(`.ibexa-tabs__tab [href="${href}"]`); | ||
const correspondingMenuItem = correspondingMenuItemLink.parentNode; | ||
|
||
correspondingMenuItem?.classList.toggle('ibexa-tabs__tab--error', hasGroupError); | ||
|
||
if (correspondingMenuItemLink) { | ||
const tabLinkId = correspondingMenuItemLink.id; | ||
const popupMenuItem = popupMenu.querySelector(`[data-tab-link-id="${tabLinkId}"]`); | ||
|
||
popupMenuItem?.classList.toggle('ibexa-popup-menu__item--error', hasGroupError); | ||
} | ||
} | ||
}); | ||
}; | ||
const invalidObserver = new MutationObserver(classInvalidChangedCallback); | ||
|
||
invalidObserver.observe(formNode, { | ||
subtree: true, | ||
attributes: true, | ||
attributeFilter: ['class'], | ||
attributeOldValue: true, | ||
}); | ||
|
||
if (popupMenu) { | ||
const classInvalidHiddenChangedCallback = (mutationList) => { | ||
mutationList.forEach(() => { | ||
const popupMenuItems = popupMenu.querySelectorAll( | ||
'.ibexa-popup-menu__item--error:not(.ibexa-popup-menu__item--hidden)', | ||
); | ||
|
||
moreBtn.classList.toggle('ibexa-tabs__tab--error', popupMenuItems.length); | ||
}); | ||
}; | ||
const invalidHiddenObserver = new MutationObserver(classInvalidHiddenChangedCallback); | ||
|
||
invalidHiddenObserver.observe(popupMenu, { | ||
subtree: true, | ||
attributes: true, | ||
attributeFilter: ['class'], | ||
attributeOldValue: true, | ||
}); | ||
} | ||
}); | ||
})(window, window.document); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.