This repository has been archived on 2024-04-05. You can view files and clone it, but cannot push or open issues/pull-requests.
score-tracker/public/scripts/manage/sport.js

58 lines
1.7 KiB
JavaScript
Raw Normal View History

import * as Data from "../data.js";
const mainHeader = document.getElementById('main-header');
const nameTextbox = document.getElementById('name-textbox');
const submitButton = document.getElementById('submit-button');
const deleteButton = document.getElementById('delete-button');
const submissionForm = document.getElementById('submission-form');
async function initializeForm() {
let params = new URLSearchParams(location.search);
let sportID = params.get('sport')
if(sportID) {
mainHeader.textContent = "Edit Sport";
const sportName = await Data.getSportName(sportID);
nameTextbox.value = sportName;
deleteButton.style.visibility = "visible";
deleteButton.disabled = false;
const sportIDInput = document.createElement('input');
sportIDInput.setAttribute('name', 'sport');
sportIDInput.setAttribute('value', sportID);
sportIDInput.setAttribute('type', 'hidden');
submissionForm.appendChild(sportIDInput);
}
nameTextbox.disabled = false;
nameTextbox.addEventListener('keyup', checkDataValidity);
}
initializeForm();
async function checkDataValidity() {
let dataIsValid = true;
if(!nameTextbox.value) dataIsValid = false;
if(dataIsValid) submitButton.disabled = false;
else submitButton.disabled = true;
2021-11-23 05:10:47 +00:00
}
async function removeSport() {
const removeInput = document.createElement('input');
removeInput.setAttribute('name', 'remove');
removeInput.setAttribute('value', 1);
removeInput.setAttribute('type', 'hidden');
submissionForm.appendChild(removeInput);
submissionForm.submit();
}
deleteButton.addEventListener('click', () => {
const verified = confirm("This sport will be removed.");
if(verified) removeSport();
});