From 3248fdf7ca15909ed0bb822bb26d9d4a2fdddaba Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Tue, 21 Jan 2025 16:14:15 -0500 Subject: [PATCH] Fixed dynamic form to correctly update the final score when submitting the form --- .../_matchstats_variable_score_input.html.erb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/views/matches/_matchstats_variable_score_input.html.erb b/app/views/matches/_matchstats_variable_score_input.html.erb index 6d562ca..b5bd851 100644 --- a/app/views/matches/_matchstats_variable_score_input.html.erb +++ b/app/views/matches/_matchstats_variable_score_input.html.erb @@ -184,7 +184,26 @@ document.addEventListener("DOMContentLoaded", () => { 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 = ""; // Reset for other win types } });