Add checkboxes to select academic years for analyze page. Stimulus controller reads the state of the checkboxes and builds the correct link to route the user

This commit is contained in:
Nelson Jovel 2022-05-31 15:49:59 -07:00
parent 607b91c795
commit 16569974a6
5 changed files with 57 additions and 4 deletions

View file

@ -4,6 +4,18 @@ import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
connect() { }
refresh(event) {
window.location = event.target.value
let location = event.target.value+ "&academic_years=";
let year_checkboxes = document.getElementsByName("year-checkbox");
let selected_years = [];
let ending = "";
year_checkboxes.forEach((item)=>{
if(item.checked) {
selected_years.push(item.id)
}
})
console.log(location)
window.location = location + selected_years.join(",")
}
}