Fix bugs in submit form dropdowns

main
sudoer777 2021-11-21 16:51:35 -07:00
parent 9b7ec5f3d6
commit e1acf1951c
1 changed files with 35 additions and 29 deletions

View File

@ -10,21 +10,9 @@ const divisionDropdown = document.getElementById('division-dropdown');
async function listSports() {
const sportsList = await Data.getSports();
sportsList.forEach(sport => {
const option = document.createElement('option');
option.text = sport.name;
option.value = sport.id;
sportDropdown.appendChild(option);
});
listSeasons();
}
listSports();
async function listSeasons() {
seasonDropdown.innerHTML = "";
const seasonsList = await Data.getSeasons();
seasonsList.forEach(season => {
@ -36,18 +24,36 @@ async function listSeasons() {
}
listSeasons();
async function listSports() {
sportDropdown.innerHTML = "";
const sportsList = await Data.getSports();
sportsList.forEach(sport => {
const option = document.createElement('option');
option.text = sport.name;
option.value = sport.id;
sportDropdown.appendChild(option);
});
listGenders();
}
listSports();
async function listGenders() {
genderDropdown.innerHTML = "";
const selectedSportID = sportDropdown.value;
const gendersList = await Data.getGenders(selectedSportID);
if(selectedSportID) {
gendersList.forEach(gender => {
const option = document.createElement('option');
option.text = (gender.name == "female") ? "Female" : (gender.name == "male") ? "Male" : "";
option.value = gender.name;
genderDropdown.appendChild(option);
});
}
listDivisions();
}
@ -58,8 +64,7 @@ async function listDivisions() {
const selectedSportID = sportDropdown.value;
const selectedGender = genderDropdown.value;
if(!selectedGender) return;
if(selectedGender) {
const divisionsList = await Data.getDivisions(selectedSportID, selectedGender);
divisionsList.forEach(division => {
@ -67,7 +72,8 @@ async function listDivisions() {
option.text = division.name;
option.value = division.id;
divisionDropdown.appendChild(option);
})
});
}
}