From 4e0444cfbf903ce50dd99552683b4fa502a1582d Mon Sep 17 00:00:00 2001 From: sherif-olaboye <123654949+sherif-olaboye@users.noreply.github.com> Date: Thu, 28 May 2026 16:44:34 +0100 Subject: [PATCH 1/4] TD-6954 selection and deselection is not working --- .../frameworks/selectoptionalcompetencies.ts | 30 +++++++++---------- .../SelectOptionalCompetencies.cshtml | 6 +++- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/DigitalLearningSolutions.Web/Scripts/frameworks/selectoptionalcompetencies.ts b/DigitalLearningSolutions.Web/Scripts/frameworks/selectoptionalcompetencies.ts index 0417a0b34a..df848d7a9c 100644 --- a/DigitalLearningSolutions.Web/Scripts/frameworks/selectoptionalcompetencies.ts +++ b/DigitalLearningSolutions.Web/Scripts/frameworks/selectoptionalcompetencies.ts @@ -1,27 +1,27 @@ document.addEventListener('DOMContentLoaded', () => { + // Explicitly tell TypeScript these are HTMLInputElements const groups = document.querySelectorAll('.nhsuk-checkboxes'); groups.forEach((group) => { + // Cast the specific input types const groupToggle = group.querySelector('input[name="GroupIds"]'); - if (!groupToggle) return; - - // All individual competency checkboxes in the group - const childCheckboxes = group.querySelectorAll( - 'input[name="SelectedCompetencyIds"]', - ); + const childCheckboxes = group.querySelectorAll('input[name="SelectedCompetencyIds"]'); - const updateState = () => { - const isChecked = groupToggle.checked; + if (!groupToggle) return; - childCheckboxes.forEach((_, index) => { - childCheckboxes[index].checked = isChecked; - }); + const syncChildren = () => { + if (groupToggle.checked) { + childCheckboxes.forEach(cb => cb.checked = true); + } }; - // Run when the group checkbox changes - groupToggle.addEventListener('change', updateState); + syncChildren(); - // Also run at page load in case some are pre-checked server-side - updateState(); + groupToggle.addEventListener('change', () => { + syncChildren(); + if (!groupToggle.checked) { + childCheckboxes.forEach(cb => cb.checked = false); + } + }); }); }); diff --git a/DigitalLearningSolutions.Web/Views/CompetencyAssessments/SelectOptionalCompetencies.cshtml b/DigitalLearningSolutions.Web/Views/CompetencyAssessments/SelectOptionalCompetencies.cshtml index cb3df401cf..13bfd420f7 100644 --- a/DigitalLearningSolutions.Web/Views/CompetencyAssessments/SelectOptionalCompetencies.cshtml +++ b/DigitalLearningSolutions.Web/Views/CompetencyAssessments/SelectOptionalCompetencies.cshtml @@ -60,7 +60,11 @@ @foreach (var competency in competencyGroup) {
- +