From 00f88dd2d6eb7fbba5ea5de008fcdca915add01a Mon Sep 17 00:00:00 2001 From: Dominic Coelho Date: Fri, 21 Sep 2018 12:51:39 +0100 Subject: [PATCH] function to prevent form submit if no boxes checked > relates #52 --- public/js/force-checked.js | 20 ++++++++++++++++++++ src/views/background.hbs | 5 +++-- src/views/partials/heading.hbs | 2 +- src/views/resources.hbs | 7 ++++--- 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 public/js/force-checked.js diff --git a/public/js/force-checked.js b/public/js/force-checked.js new file mode 100644 index 0000000..d6bf275 --- /dev/null +++ b/public/js/force-checked.js @@ -0,0 +1,20 @@ +// Script to make it compulsory to have at least one item ticked + +document.getElementById("submit-form").addEventListener("submit", forceChecked); + +function forceChecked(e){ + var resourceOrSession = ""; + + if(document.getElementById("title-heading").textContent == "Background") { + resourceOrSession = "background" + } else { + resourceOrSession = "resource" + } + + if (Object.keys(sessionStorage).toString().includes(resourceOrSession)){ + return true; + } else { + e.preventDefault(); + window.alert("Please select at least one item to receive your results") + } +} \ No newline at end of file diff --git a/src/views/background.hbs b/src/views/background.hbs index d945d1d..cd0c06b 100644 --- a/src/views/background.hbs +++ b/src/views/background.hbs @@ -84,10 +84,11 @@
-
+
- \ No newline at end of file + + \ No newline at end of file diff --git a/src/views/partials/heading.hbs b/src/views/partials/heading.hbs index 8facd51..02afbdd 100644 --- a/src/views/partials/heading.hbs +++ b/src/views/partials/heading.hbs @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/src/views/resources.hbs b/src/views/resources.hbs index 1b59caf..c4c6d9d 100644 --- a/src/views/resources.hbs +++ b/src/views/resources.hbs @@ -42,10 +42,11 @@
-
- + +
- \ No newline at end of file + + \ No newline at end of file