Skip to content

Commit 1c8ee61

Browse files
authored
Merge pull request #202 from nhsuk/checkbox-fix
Add script to mark unchecked boxes
2 parents ce12df7 + 1618d8b commit 1c8ee61

File tree

5 files changed

+716
-679
lines changed

5 files changed

+716
-679
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# NHS.UK prototype kit Changelog
22

3+
## 4.6.4 - 25 August 2021
4+
5+
- Add script to fix bug with unchecked checkboxes and separate bug when only one checkbox is selected.
6+
- Update package dependencies to latest versions
7+
38
## 4.6.3 - 24 August 2021
49

510
:wrench: **Fixes**
611

712
- Use the correct name for the NHS digital service manual Slack instance
813
- Fix GitHub actions/Azure DevOps release pipelines [Issue 180](https://github.com/nhsuk/nhsuk-prototype-kit/issues/180)
9-
1014
## 4.6.2 - 24 August 2021
1115

1216
:wrench: **Fixes**
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// On form submit, add hidden inputs for checkboxes so the server knows if
2+
// they've been unchecked. This means we can automatically store and update
3+
// all form data on the server, including checkboxes that are checked, then
4+
// later unchecked
5+
const forms = document.querySelectorAll("form")
6+
7+
for (let form of forms) {
8+
form.addEventListener("submit", () => {
9+
const checkboxes = form.querySelectorAll("input[type='checkbox']")
10+
const names = {}
11+
12+
checkboxes.forEach(checkbox => {
13+
if (!names[checkbox.name]) {
14+
names[checkbox.name] = true
15+
16+
const input = document.createElement("input")
17+
input.setAttribute("type", "hidden")
18+
input.setAttribute("name", checkbox.name)
19+
input.setAttribute("value", "_unchecked")
20+
form.appendChild(input)
21+
}
22+
})
23+
})
24+
}

app/views/includes/scripts.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<script src="/js/jquery-3.5.1.min.js"></script>
22
<script src="/js/main.js"></script>
3+
{% if useAutoStoreData %}
4+
<script src="/js/auto-store-data.js"></script>
5+
{% endif %}
36

47
<!-- Add any custom scripts -->

0 commit comments

Comments
 (0)