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() { async function listSeasons() {
seasonDropdown.innerHTML = "";
const seasonsList = await Data.getSeasons(); const seasonsList = await Data.getSeasons();
seasonsList.forEach(season => { seasonsList.forEach(season => {
@ -36,18 +24,36 @@ async function listSeasons() {
} }
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() { async function listGenders() {
genderDropdown.innerHTML = ""; genderDropdown.innerHTML = "";
const selectedSportID = sportDropdown.value; const selectedSportID = sportDropdown.value;
const gendersList = await Data.getGenders(selectedSportID); const gendersList = await Data.getGenders(selectedSportID);
gendersList.forEach(gender => { if(selectedSportID) {
const option = document.createElement('option'); gendersList.forEach(gender => {
option.text = (gender.name == "female") ? "Female" : (gender.name == "male") ? "Male" : ""; const option = document.createElement('option');
option.value = gender.name; option.text = (gender.name == "female") ? "Female" : (gender.name == "male") ? "Male" : "";
genderDropdown.appendChild(option); option.value = gender.name;
}); genderDropdown.appendChild(option);
});
}
listDivisions(); listDivisions();
} }
@ -58,16 +64,16 @@ async function listDivisions() {
const selectedSportID = sportDropdown.value; const selectedSportID = sportDropdown.value;
const selectedGender = genderDropdown.value; const selectedGender = genderDropdown.value;
if(!selectedGender) return; if(selectedGender) {
const divisionsList = await Data.getDivisions(selectedSportID, selectedGender);
const divisionsList = await Data.getDivisions(selectedSportID, selectedGender); divisionsList.forEach(division => {
const option = document.createElement('option');
divisionsList.forEach(division => { option.text = division.name;
const option = document.createElement('option'); option.value = division.id;
option.text = division.name; divisionDropdown.appendChild(option);
option.value = division.id; });
divisionDropdown.appendChild(option); }
})
} }