Skip to content

Commit

Permalink
function to prevent form submit if no boxes checked > relates #52
Browse files Browse the repository at this point in the history
  • Loading branch information
VirtualDOMinic committed Sep 21, 2018
1 parent d8651e7 commit 00f88dd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
20 changes: 20 additions & 0 deletions public/js/force-checked.js
Original file line number Diff line number Diff line change
@@ -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")
}
}
5 changes: 3 additions & 2 deletions src/views/background.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@
</section>
<section class='grid-row'>
<div id='bottom-section' class='centered-column centered-content secondary-background thirtytwo-padding fixed-height-double-h1 bottom-padding-lft'>
<form action='/resources' class='centered-content'>
<form action='/resources' class='centered-content' id="submit-form">
<button class="govuk-button">Get resources</button>
</form>
</div>
</section>

<script src='js/checkboxlocalstoragebackground.js'></script>
<script src='js/checkboxlocalstoragebackground.js'></script>
<script src='js/force-checked.js'></script>
2 changes: 1 addition & 1 deletion src/views/partials/heading.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<nav class='grid-row'>
<div class='centered-column centered-content secondary-background thirtytwo-padding fixed-height-double-h1 padding-lft'>
<h1>{{title}}</h1>
<h1 id="title-heading">{{title}}</h1>
</div>
</nav>
7 changes: 4 additions & 3 deletions src/views/resources.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@
</section>
<section class='grid-row'>
<div id='bottom-section' class='centered-column centered-content secondary-background thirtytwo-padding fixed-height-double-h1 bottom-padding-lft'>
<form action='/more-info' class='centered-content'>
<button class="govuk-button">Next!</button>
<form action='/more-info' class='centered-content' id="submit-form">
<button class="govuk-button" >Next!</button>
</form>
</div>
</section>

<script src='js/checkboxlocalstorageresources.js'></script>
<script src='js/checkboxlocalstorageresources.js'></script>
<script src='js/force-checked.js'></script>

0 comments on commit 00f88dd

Please sign in to comment.