Add function to list teams on submit form
parent
edfd42a623
commit
27d05752b5
|
@ -21,3 +21,9 @@ export async function getDivisions(sportID, gender) {
|
|||
const divisionsList = await response.json();
|
||||
return divisionsList;
|
||||
}
|
||||
|
||||
export async function getTeams(sportID) {
|
||||
const response = await fetch(`/data/teams?sport=${+sportID}`);
|
||||
const teamsList = await response.json();
|
||||
return teamsList;
|
||||
}
|
|
@ -5,6 +5,8 @@ const sportDropdown = document.getElementById('sport-dropdown');
|
|||
const seasonDropdown = document.getElementById('year-dropdown');
|
||||
const genderDropdown = document.getElementById('gender-dropdown');
|
||||
const divisionDropdown = document.getElementById('division-dropdown');
|
||||
const team1Dropdown = document.getElementById('team1-dropdown');
|
||||
const team2Dropdown = document.getElementById('team2-dropdown');
|
||||
|
||||
|
||||
|
||||
|
@ -37,6 +39,7 @@ async function listSports() {
|
|||
});
|
||||
|
||||
listGenders();
|
||||
listTeams();
|
||||
}
|
||||
listSports();
|
||||
|
||||
|
@ -76,9 +79,35 @@ async function listDivisions() {
|
|||
}
|
||||
}
|
||||
|
||||
async function listTeams() {
|
||||
team1Dropdown.innerHTML = "";
|
||||
team2Dropdown.innerHTML = "";
|
||||
|
||||
const selectedSportID = sportDropdown.value;
|
||||
|
||||
if(selectedSportID) {
|
||||
const teamsList = await Data.getTeams(selectedSportID);
|
||||
|
||||
teamsList.forEach(team => {
|
||||
const optionT1 = document.createElement('option');
|
||||
optionT1.text = team.name;
|
||||
optionT1.value = team.id;
|
||||
team1Dropdown.appendChild(optionT1);
|
||||
|
||||
const optionT2 = document.createElement('option');
|
||||
optionT2.text = team.name;
|
||||
optionT2.value = team.id;
|
||||
team2Dropdown.appendChild(optionT2);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
sportDropdown.onchange = listGenders;
|
||||
|
||||
sportDropdown.onchange = (() => {
|
||||
listGenders();
|
||||
listTeams();
|
||||
});
|
||||
genderDropdown.onchange = listDivisions;
|
|
@ -4,6 +4,7 @@ var sports = require('../database/scores/sports');
|
|||
var seasons = require('../database/scores/seasons');
|
||||
var genders = require('../database/scores/genders');
|
||||
var divisions = require('../database/scores/divisions');
|
||||
var teams = require('../database/scores/teams');
|
||||
|
||||
|
||||
router.get('/sports', function(req, res, next) {
|
||||
|
@ -28,4 +29,9 @@ router.get('/divisions', function(req, res, next) {
|
|||
.then(data => res.json(data));
|
||||
})
|
||||
|
||||
router.get('/teams', function(req, res, next) {
|
||||
teams.retrieveBySport(req.query.sport)
|
||||
.then(data => res.json(data));
|
||||
})
|
||||
|
||||
module.exports = router;
|
Reference in New Issue