Add function to list sports in submit form dropdown
This commit is contained in:
		
							parent
							
								
									8c3ffcc5fa
								
							
						
					
					
						commit
						30ddb13ec6
					
				
					 4 changed files with 30 additions and 5 deletions
				
			
		
							
								
								
									
										5
									
								
								public/scripts/data.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								public/scripts/data.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | ||||||
|  | export async function getSports() { | ||||||
|  |     const response = await fetch('/data/sports'); | ||||||
|  |     const sportsList = await response.json(); | ||||||
|  |     return sportsList; | ||||||
|  | } | ||||||
|  | @ -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(); | ||||||
|  | @ -1,10 +1,11 @@ | ||||||
| var express = require('express'); | var express = require('express'); | ||||||
| var router = express.Router(); | var router = express.Router(); | ||||||
| var database = require('../database/database'); | var sports = require('../database/scores/sports'); | ||||||
| 
 | 
 | ||||||
| /* GET submit page. */ | /* GET submit page. */ | ||||||
| router.get('/', function(req, res, next) { | router.get('/sports', function(req, res, next) { | ||||||
|   res.json( { message : "test" }); |     sports.retrieveAll() | ||||||
|  |         .then(data => res.json(data)); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| module.exports = router; | module.exports = router; | ||||||
|  | @ -15,7 +15,6 @@ block content | ||||||
|       label Sport |       label Sport | ||||||
|       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")  | ||||||
|           option(value="Basketball" selected) Basketball |  | ||||||
|         select#gender-dropdown(name="gender") |         select#gender-dropdown(name="gender") | ||||||
|           option(value="Male" selected) Male  |           option(value="Male" selected) Male  | ||||||
|           option(value="Female") Female |           option(value="Female") Female | ||||||
|  | @ -41,4 +40,4 @@ block content | ||||||
|       button(type="submit") Submit |       button(type="submit") Submit | ||||||
| 
 | 
 | ||||||
| block scripts  | block scripts  | ||||||
|   script(src='/scripts/submit.js') |   script(src='/scripts/submit.js' type="module") | ||||||
		Reference in a new issue