support: toggle correct elements on page load
This commit is contained in:
parent
bc408e3374
commit
4e2e8e9a57
1 changed files with 13 additions and 7 deletions
|
@ -1,10 +1,16 @@
|
|||
import { show, hide, delegate } from '@utils';
|
||||
|
||||
delegate('change', '#contact-form #type', event => {
|
||||
const type = event.target.value;
|
||||
const visibleElements = `[data-contact-type-only="${type}"]`;
|
||||
const hiddenElements = `[data-contact-type-only]:not([data-contact-type-only="${type}"])`;
|
||||
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}"])`;
|
||||
|
||||
document.querySelectorAll(visibleElements).forEach(show);
|
||||
document.querySelectorAll(hiddenElements).forEach(hide);
|
||||
});
|
||||
document.querySelectorAll(visibleElements).forEach(show);
|
||||
document.querySelectorAll(hiddenElements).forEach(hide);
|
||||
}
|
||||
}
|
||||
|
||||
addEventListener('turbolinks:load', updateContactElementsVisibility);
|
||||
delegate('change', '#contact-form #type', updateContactElementsVisibility);
|
||||
|
|
Loading…
Reference in a new issue