mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-04 13:43:48 +00:00
Added a daily recurring job to cleanup tournaments. Fixed final score fields not loading without page refresh on mat stats page and added a cypress test for it.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<script>
|
||||
// ############### Score field changer and form validation
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
function initializeScoreFields() {
|
||||
const winTypeSelect = document.getElementById("match_win_type");
|
||||
const winnerSelect = document.getElementById("match_winner_id");
|
||||
const submitButton = document.getElementById("update-match-btn");
|
||||
@@ -9,6 +9,9 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
const validationAlerts = document.getElementById("validation-alerts");
|
||||
const pinTimeTip = document.getElementById("pin-time-tip");
|
||||
|
||||
// If elements don't exist, don't proceed
|
||||
if (!winTypeSelect || !dynamicScoreInput || !finalScoreField) return;
|
||||
|
||||
// Variables to persist scores across win type changes
|
||||
let storedScores = {
|
||||
winnerScore: "0",
|
||||
@@ -111,7 +114,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
|
||||
function validateForm() {
|
||||
const winType = winTypeSelect.value;
|
||||
const winner = winnerSelect.value;
|
||||
const winner = winnerSelect ? winnerSelect.value : null;
|
||||
let isValid = true;
|
||||
let alertMessage = "";
|
||||
|
||||
@@ -156,57 +159,65 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
alertMessage += "Please select a winner.<br>";
|
||||
}
|
||||
|
||||
if (!isValid) {
|
||||
validationAlerts.innerHTML = alertMessage;
|
||||
validationAlerts.style.display = "block";
|
||||
} else {
|
||||
validationAlerts.innerHTML = ""; // Clear alerts
|
||||
validationAlerts.style.display = "none";
|
||||
if (validationAlerts) {
|
||||
if (!isValid) {
|
||||
validationAlerts.innerHTML = alertMessage;
|
||||
validationAlerts.style.display = "block";
|
||||
} else {
|
||||
validationAlerts.innerHTML = ""; // Clear alerts
|
||||
validationAlerts.style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
submitButton.disabled = !isValid;
|
||||
if (submitButton) {
|
||||
submitButton.disabled = !isValid;
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelector("form").addEventListener("submit", (event) => {
|
||||
const winType = winTypeSelect.value;
|
||||
if (document.querySelector("form")) {
|
||||
document.querySelector("form").addEventListener("submit", (event) => {
|
||||
const winType = winTypeSelect.value;
|
||||
|
||||
if (winType === "Pin") {
|
||||
const minuteInput = document.getElementById("minutes");
|
||||
const secondInput = document.getElementById("seconds");
|
||||
if (winType === "Pin") {
|
||||
const minuteInput = document.getElementById("minutes");
|
||||
const secondInput = document.getElementById("seconds");
|
||||
|
||||
if (minuteInput && secondInput) {
|
||||
const minutes = minuteInput.value.padStart(2, "0");
|
||||
const seconds = secondInput.value.padStart(2, "0");
|
||||
finalScoreField.value = `${minutes}:${seconds}`;
|
||||
if (minuteInput && secondInput) {
|
||||
const minutes = minuteInput.value.padStart(2, "0");
|
||||
const seconds = secondInput.value.padStart(2, "0");
|
||||
finalScoreField.value = `${minutes}:${seconds}`;
|
||||
} else {
|
||||
finalScoreField.value = ""; // Clear if no inputs
|
||||
}
|
||||
} else if (
|
||||
winType === "Decision" ||
|
||||
winType === "Major" ||
|
||||
winType === "Tech Fall"
|
||||
) {
|
||||
const winnerScoreInput = document.getElementById("winner-score");
|
||||
const loserScoreInput = document.getElementById("loser-score");
|
||||
|
||||
if (winnerScoreInput && loserScoreInput) {
|
||||
const winnerScore = winnerScoreInput.value || "0";
|
||||
const loserScore = loserScoreInput.value || "0";
|
||||
finalScoreField.value = `${winnerScore}-${loserScore}`;
|
||||
} else {
|
||||
finalScoreField.value = ""; // Clear if no inputs
|
||||
}
|
||||
} else {
|
||||
finalScoreField.value = ""; // Clear if no inputs
|
||||
finalScoreField.value = ""; // Reset for other win types
|
||||
}
|
||||
} else if (
|
||||
winType === "Decision" ||
|
||||
winType === "Major" ||
|
||||
winType === "Tech Fall"
|
||||
) {
|
||||
const winnerScoreInput = document.getElementById("winner-score");
|
||||
const loserScoreInput = document.getElementById("loser-score");
|
||||
|
||||
if (winnerScoreInput && loserScoreInput) {
|
||||
const winnerScore = winnerScoreInput.value || "0";
|
||||
const loserScore = loserScoreInput.value || "0";
|
||||
finalScoreField.value = `${winnerScore}-${loserScore}`;
|
||||
} else {
|
||||
finalScoreField.value = ""; // Clear if no inputs
|
||||
}
|
||||
} else {
|
||||
finalScoreField.value = ""; // Reset for other win types
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
winTypeSelect.addEventListener("change", updateScoreInput);
|
||||
winnerSelect.addEventListener("change", validateForm);
|
||||
if (winnerSelect) {
|
||||
winnerSelect.addEventListener("change", validateForm);
|
||||
}
|
||||
|
||||
updateScoreInput();
|
||||
validateForm();
|
||||
});
|
||||
}
|
||||
|
||||
// Helper function to create text inputs
|
||||
function createTextInput(id, placeholder, label) {
|
||||
@@ -226,4 +237,8 @@ function createTextInput(id, placeholder, label) {
|
||||
container.appendChild(input);
|
||||
return container;
|
||||
}
|
||||
|
||||
// Initialize on both DOMContentLoaded and turbolinks:load
|
||||
document.addEventListener("DOMContentLoaded", initializeScoreFields);
|
||||
document.addEventListener("turbolinks:load", initializeScoreFields);
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user