From f958cfff9b765285aac23d4465d7476eb6b4f795 Mon Sep 17 00:00:00 2001 From: Tim Parenti Date: Sun, 3 Mar 2019 22:37:24 -0500 Subject: [PATCH] Disable judges' game panel buttons if required inputs aren't set. Specifically, "start game" and "set flags" buttons. Resolves #15. --- templates/judge.html | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/templates/judge.html b/templates/judge.html index 8e7047b..47868e1 100644 --- a/templates/judge.html +++ b/templates/judge.html @@ -29,6 +29,29 @@ return new Date(secs * 1000).toLocaleTimeString(); } + function validateInputs() { + var error = false; + + $(this).closest("form").find(".input-required").each(function () { + if ($.trim(this.value) === "") { + error = true; + } + }); + + $(this).closest("form").find(".radio-required").each(function () { + if ($("input:radio:checked", this).length < 1) { + error = true; + } + }); + + if (error) { + $(this).closest("form").find("button:submit").attr("disabled", "disabled"); + } + else { + $(this).closest("form").find("button:submit").removeAttr("disabled"); + } + } + function postForm(e) { e.preventDefault(); // Prevent normal form submission @@ -339,6 +362,10 @@ // Enable all Bootstrap popovers $("[data-toggle='tooltip']").tooltip(); + // Form input validation actions + $(".input-required").on("input", validateInputs); + $(".radio-required").on("input", validateInputs); + // Form submit actions $(".form-ajax-submit").submit(postForm); $(".form-no-submit").submit(function (e) {e.preventDefault();}); @@ -749,7 +776,7 @@

Set flags to 0 - @@ -823,7 +850,7 @@

-