2019-02-21 17:50:18 +01:00
|
|
|
import { show, hide, delegate } from '@utils';
|
|
|
|
|
2019-03-14 11:41:54 +01:00
|
|
|
function updateContactElementsVisibility() {
|
|
|
|
const contactSelect = document.querySelector('#contact-form #type');
|
|
|
|
if (contactSelect) {
|
|
|
|
const type = contactSelect.value;
|
|
|
|
const visibleElements = `[data-contact-type-only="${type}"]`;
|
|
|
|
const hiddenElements = `[data-contact-type-only]:not([data-contact-type-only="${type}"])`;
|
2019-02-21 17:50:18 +01:00
|
|
|
|
2019-03-14 11:41:54 +01:00
|
|
|
document.querySelectorAll(visibleElements).forEach(show);
|
|
|
|
document.querySelectorAll(hiddenElements).forEach(hide);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-01 15:22:37 +02:00
|
|
|
addEventListener('ds:page:update', updateContactElementsVisibility);
|
2019-03-14 11:41:54 +01:00
|
|
|
delegate('change', '#contact-form #type', updateContactElementsVisibility);
|