Add function to get genders per sport in submit form

main
sudoer777 2021-11-21 16:24:43 -07:00
parent e5b1791259
commit ff070acdf7
5 changed files with 41 additions and 6 deletions

View File

@ -13,18 +13,22 @@ async function retrieveBySport(sportID) {
const gendersList = []; const gendersList = [];
if(table.length() == 2) { if(table.length == 0) {
return gendersList;
}
if(table.length == 2) {
gendersList.push(genders.female); gendersList.push(genders.female);
gendersList.push(genders.male); gendersList.push(genders.male);
return gendersList;
} }
else if(table[0][0] = "F") { else if(table[0][0] = "F") {
gendersList.push(genders.female); gendersList.push(genders.female);
return gendersList;
} }
else if(table[0][0] = "M") { else if(table[0][0] = "M") {
gendersList.push(genders.male); gendersList.push(genders.male);
return gendersList;
} }
return gendersList;
} }

View File

@ -8,4 +8,10 @@ export async function getSeasons() {
const response = await fetch('/data/seasons'); const response = await fetch('/data/seasons');
const seasonsList = await response.json(); const seasonsList = await response.json();
return seasonsList; return seasonsList;
}
export async function getGenders(sportID) {
const response = await fetch(`/data/genders?sport=${+sportID}`);
const gendersList = await response.json();
return gendersList;
} }

View File

@ -3,6 +3,7 @@ import * as Data from "./data.js";
const sportDropdown = document.getElementById('sport-dropdown'); const sportDropdown = document.getElementById('sport-dropdown');
const seasonDropdown = document.getElementById('year-dropdown'); const seasonDropdown = document.getElementById('year-dropdown');
const genderDropdown = document.getElementById('gender-dropdown');
@ -30,4 +31,24 @@ async function listSeasons() {
seasonDropdown.appendChild(option); seasonDropdown.appendChild(option);
}); });
} }
listSeasons(); listSeasons();
async function listGenders() {
genderDropdown.innerHTML = "";
const selectedSportID = sportDropdown.value;
const gendersList = await Data.getGenders(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);
});
}
sportDropdown.onchange = listGenders;

View File

@ -2,6 +2,7 @@ var express = require('express');
var router = express.Router(); var router = express.Router();
var sports = require('../database/scores/sports'); var sports = require('../database/scores/sports');
var seasons = require('../database/scores/seasons'); var seasons = require('../database/scores/seasons');
var genders = require('../database/scores/genders');
router.get('/sports', function(req, res, next) { router.get('/sports', function(req, res, next) {
@ -14,4 +15,9 @@ router.get('/seasons', function(req, res, next) {
.then(data => res.json(data)); .then(data => res.json(data));
}) })
router.get('/genders', function(req, res, next) {
genders.retrieveBySport(req.query.sport)
.then(data => res.json(data));
})
module.exports = router; module.exports = router;

View File

@ -15,8 +15,6 @@ block content
span(class='form-section-input') span(class='form-section-input')
select#sport-dropdown(name="sport" class="main-dropdown") select#sport-dropdown(name="sport" class="main-dropdown")
select#gender-dropdown(name="gender") select#gender-dropdown(name="gender")
option(value="Male" selected) Male
option(value="Female") Female
select#division-dropdown(name="division") select#division-dropdown(name="division")
option(value="Varsity") Varsity option(value="Varsity") Varsity
option(value="JV-A") JV-A option(value="JV-A") JV-A