parent
cff51bc9f6
commit
bb6f6306c4
@ -1,14 +1,18 @@
|
|||||||
export function initializeListenersForNavDropdowns(){
|
export function initializeListenersForNavDropdowns() {
|
||||||
document.addEventListener("turbolinks:load", function() {
|
document.addEventListener("turbolinks:load", function () {
|
||||||
const schoolDropdown = document.querySelector('#select-school');
|
const schoolDropdown = document.querySelector("#select-school");
|
||||||
if (schoolDropdown) {
|
if (schoolDropdown) {
|
||||||
document.querySelector('#select-school').addEventListener('change', (event) => {
|
document
|
||||||
window.location = event.target.value;
|
.querySelector("#select-school")
|
||||||
});
|
.addEventListener("change", (event) => {
|
||||||
|
window.location = event.target.value;
|
||||||
|
});
|
||||||
|
|
||||||
document.querySelector('#select-district').addEventListener('change', (event) => {
|
document
|
||||||
window.location = event.target.value;
|
.querySelector("#select-district")
|
||||||
});
|
.addEventListener("change", (event) => {
|
||||||
|
window.location = event.target.value;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,28 +1,33 @@
|
|||||||
export function initializeListenersForHomeDropdowns(){
|
export function initializeListenersForHomeDropdowns() {
|
||||||
document.addEventListener('turbolinks:load', () => {
|
document.addEventListener("turbolinks:load", () => {
|
||||||
const districtDropdown = document.querySelector('#district-dropdown');
|
const districtDropdown = document.querySelector("#district-dropdown");
|
||||||
if (districtDropdown) {
|
if (districtDropdown) {
|
||||||
districtDropdown.addEventListener('change', event => {
|
districtDropdown.addEventListener("change", (event) => {
|
||||||
const schoolDropdown = document.querySelector('#school-dropdown');
|
const schoolDropdown = document.querySelector("#school-dropdown");
|
||||||
|
|
||||||
const districtId = Number(event.target.value);
|
const districtId = Number(event.target.value);
|
||||||
|
|
||||||
const schoolsInDistrict = window.schools.filter(school => school.district_id === districtId);
|
const schoolsInDistrict = window.schools.filter(
|
||||||
|
(school) => school.district_id === districtId
|
||||||
|
);
|
||||||
|
|
||||||
schoolsInDistrict.forEach(school => {
|
schoolsInDistrict.forEach((school) => {
|
||||||
const optionElem = document.createElement('option');
|
const optionElem = document.createElement("option");
|
||||||
optionElem.setAttribute('value', school.url);
|
optionElem.setAttribute("value", school.url);
|
||||||
const schoolNameNode = document.createTextNode(school.name);
|
const schoolNameNode = document.createTextNode(school.name);
|
||||||
optionElem.appendChild(schoolNameNode);
|
optionElem.appendChild(schoolNameNode);
|
||||||
schoolDropdown.appendChild(optionElem);
|
schoolDropdown.appendChild(optionElem);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
document.querySelector('button[data-id="go-to-school"]').addEventListener('click', event => {
|
document
|
||||||
const selectedSchoolURL = document.querySelector('#school-dropdown').value;
|
.querySelector('button[data-id="go-to-school"]')
|
||||||
window.location = selectedSchoolURL;
|
.addEventListener("click", (event) => {
|
||||||
});
|
const selectedSchoolURL =
|
||||||
}
|
document.querySelector("#school-dropdown").value;
|
||||||
});
|
window.location = selectedSchoolURL;
|
||||||
return true;
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in new issue