Add function to list sports in submit form dropdown

main
sudoer777 2021-11-21 15:30:54 -07:00
parent 8c3ffcc5fa
commit 30ddb13ec6
4 changed files with 30 additions and 5 deletions

View File

@ -0,0 +1,5 @@
export async function getSports() {
const response = await fetch('/data/sports');
const sportsList = await response.json();
return sportsList;
}

View File

@ -0,0 +1,20 @@
import * as Data from "./data.js";
const sportDropdown = document.getElementById('sport-dropdown');
async function listSports() {
let sportsList = await Data.getSports();
sportsList.forEach(sport => {
const option = document.createElement('option');
option.text = sport.name;
option.value = sport.id;
sportDropdown.appendChild(option);
});
}
listSports();

View File

@ -1,10 +1,11 @@
var express = require('express');
var router = express.Router();
var database = require('../database/database');
var sports = require('../database/scores/sports');
/* GET submit page. */
router.get('/', function(req, res, next) {
res.json( { message : "test" });
router.get('/sports', function(req, res, next) {
sports.retrieveAll()
.then(data => res.json(data));
});
module.exports = router;

View File

@ -15,7 +15,6 @@ block content
label Sport
span(class='form-section-input')
select#sport-dropdown(name="sport" class="main-dropdown")
option(value="Basketball" selected) Basketball
select#gender-dropdown(name="gender")
option(value="Male" selected) Male
option(value="Female") Female
@ -41,4 +40,4 @@ block content
button(type="submit") Submit
block scripts
script(src='/scripts/submit.js')
script(src='/scripts/submit.js' type="module")