Add data validity check for adding game
parent
cceda089c0
commit
b1637d97bc
|
@ -28,33 +28,25 @@ async function initializeForm() {
|
|||
Form.addHiddenValue('game', gameID, submissionForm);
|
||||
|
||||
Form.populateSeasons(seasonDropdown, game.seasonID);
|
||||
Data.getDivision(game.divisionID)
|
||||
.then(data => {
|
||||
Form.populateSports(sportDropdown, data.sportID)
|
||||
.then(() => {
|
||||
Form.populateGenders(genderDropdown, sportDropdown.value, data.gender.name)
|
||||
.then(() => {
|
||||
Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value, game.divisionID);
|
||||
});
|
||||
Form.populateTeams(team1Dropdown, sportDropdown.value, game.team1ID);
|
||||
Form.populateTeams(team2Dropdown, sportDropdown.value, game.team2ID);
|
||||
});
|
||||
});
|
||||
const data = await Data.getDivision(game.divisionID)
|
||||
await Form.populateSports(sportDropdown, data.sportID)
|
||||
await Form.populateGenders(genderDropdown, sportDropdown.value, data.gender.name)
|
||||
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value, game.divisionID);
|
||||
await Form.populateTeams(team1Dropdown, sportDropdown.value, game.team1ID);
|
||||
await Form.populateTeams(team2Dropdown, sportDropdown.value, game.team2ID);
|
||||
|
||||
dateInput.value = game.date;
|
||||
team1ScoreTextbox.value = game.team1Score;
|
||||
team2ScoreTextbox.value = game.team2Score;
|
||||
}
|
||||
else {
|
||||
Form.populateSeasons(seasonDropdown);
|
||||
Form.populateSports(sportDropdown)
|
||||
.then(() => {
|
||||
Form.populateGenders(genderDropdown, sportDropdown.value)
|
||||
.then(() => {
|
||||
Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
|
||||
});
|
||||
Form.populateTeams(team1Dropdown, sportDropdown.value);
|
||||
Form.populateTeams(team2Dropdown, sportDropdown.value);
|
||||
});
|
||||
await Form.populateSeasons(seasonDropdown);
|
||||
await Form.populateSports(sportDropdown)
|
||||
await Form.populateGenders(genderDropdown, sportDropdown.value)
|
||||
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
|
||||
await Form.populateTeams(team1Dropdown, sportDropdown.value);
|
||||
await Form.populateTeams(team2Dropdown, sportDropdown.value);
|
||||
|
||||
dateInput.value = (new Date()).toISOString().slice(0,10);
|
||||
}
|
||||
seasonDropdown.disabled = false;
|
||||
|
@ -66,21 +58,49 @@ async function initializeForm() {
|
|||
team2Dropdown.disabled = false;
|
||||
team1ScoreTextbox.disabled = false;
|
||||
team2ScoreTextbox.disabled = false;
|
||||
submitButton.disabled = false;
|
||||
|
||||
sportDropdown.onchange = () => {
|
||||
Form.populateGenders(genderDropdown, sportDropdown.value)
|
||||
.then(() => {
|
||||
Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
|
||||
});
|
||||
Form.populateTeams(team1Dropdown, sportDropdown.value);
|
||||
Form.populateTeams(team2Dropdown, sportDropdown.value);
|
||||
sportDropdown.onchange = async () => {
|
||||
await Form.populateGenders(genderDropdown, sportDropdown.value)
|
||||
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
|
||||
await Form.populateTeams(team1Dropdown, sportDropdown.value);
|
||||
await Form.populateTeams(team2Dropdown, sportDropdown.value);
|
||||
checkDataValidity();
|
||||
};
|
||||
|
||||
genderDropdown.onchange = () => {
|
||||
Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
|
||||
genderDropdown.onchange = async () => {
|
||||
await Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
|
||||
checkDataValidity();
|
||||
};
|
||||
|
||||
dateInput.addEventListener('keyup', checkDataValidity);
|
||||
team1Dropdown.onchange = checkDataValidity;
|
||||
team1ScoreTextbox.addEventListener('keyup', checkDataValidity);
|
||||
team2Dropdown.onchange = checkDataValidity;
|
||||
team2ScoreTextbox.addEventListener('keyup', checkDataValidity);
|
||||
|
||||
checkDataValidity();
|
||||
}
|
||||
initializeForm();
|
||||
|
||||
async function checkDataValidity() {
|
||||
let dataIsValid = true;
|
||||
|
||||
const seasonHasContent = seasonDropdown.options.length;
|
||||
const sportHasContent = sportDropdown.options.length;
|
||||
const genderHasContent = genderDropdown.options.length;
|
||||
const divisionHasContent = divisionDropdown.options.length;
|
||||
const team1HasContent = team1Dropdown.options.length;
|
||||
const team2HasContent = team2Dropdown.options.length;
|
||||
|
||||
if(!seasonHasContent || !sportHasContent || !genderHasContent || !divisionHasContent || !team1HasContent || !team2HasContent) dataIsValid = false;
|
||||
|
||||
if(team1Dropdown.selectedIndex == team2Dropdown.selectedIndex) dataIsValid = false;
|
||||
|
||||
if(team1ScoreTextbox.value == "" || team2ScoreTextbox.value == "") dataIsValid = false;
|
||||
|
||||
if(dateInput.value == "") dataIsValid = false;
|
||||
|
||||
submitButton.disabled = !dataIsValid;
|
||||
}
|
||||
|
||||
Form.addRemoveFunction(deleteButton, submissionForm, "game");
|
||||
|
|
Reference in New Issue