mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-10 16:00:33 -07:00
Add JS tests to verify school and district dropdowns.
This commit is contained in:
parent
2d4ba042f9
commit
6320d5633f
12 changed files with 219 additions and 74 deletions
|
|
@ -1,9 +1,12 @@
|
|||
document.addEventListener("DOMContentLoaded", function() {
|
||||
document.querySelector('#select-school').addEventListener('change', (event) => {
|
||||
window.location = event.target.value;
|
||||
});
|
||||
document.addEventListener("turbolinks:load", function() {
|
||||
const schoolDropdown = document.querySelector('#select-school');
|
||||
if (schoolDropdown) {
|
||||
document.querySelector('#select-school').addEventListener('change', (event) => {
|
||||
window.location = event.target.value;
|
||||
});
|
||||
|
||||
document.querySelector('#select-district').addEventListener('change', (event) => {
|
||||
window.location = event.target.value;
|
||||
});
|
||||
document.querySelector('#select-district').addEventListener('change', (event) => {
|
||||
window.location = event.target.value;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
25
app/assets/javascripts/home.js
Normal file
25
app/assets/javascripts/home.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const districtDropdown = document.querySelector('#district-dropdown');
|
||||
if (districtDropdown) {
|
||||
districtDropdown.addEventListener('change', event => {
|
||||
const schoolDropdown = document.querySelector('#school-dropdown');
|
||||
|
||||
const districtId = Number(event.target.value);
|
||||
|
||||
const schoolsInDistrict = window.schools.filter(school => school.district_id === districtId);
|
||||
|
||||
schoolsInDistrict.forEach(school => {
|
||||
const optionElem = document.createElement('option');
|
||||
optionElem.setAttribute('value', school.url);
|
||||
const schoolNameNode = document.createTextNode(school.name);
|
||||
optionElem.appendChild(schoolNameNode);
|
||||
schoolDropdown.appendChild(optionElem);
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelector('button[data-id="go-to-school"]').addEventListener('click', event => {
|
||||
const selectedSchoolURL = document.querySelector('#school-dropdown').value;
|
||||
window.location = selectedSchoolURL;
|
||||
});
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue