Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@
const groups = document.querySelectorAll<HTMLDivElement>('.nhsuk-checkboxes');

groups.forEach((group) => {
const groupToggle = group.querySelector<HTMLInputElement>('input[name="GroupIds"]');
if (!groupToggle) return;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have we removed this? it seems like a sensible quite error catch?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I see it has moved to line 13


const groupToggle =
group.querySelector<HTMLInputElement>('input[name="GroupIds"]');
// All individual competency checkboxes in the group
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than removing code comments, it would be useful to update them to explain what is changing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done the comment has been re-added

const childCheckboxes = group.querySelectorAll<HTMLInputElement>(
'input[name="SelectedCompetencyIds"]',
);
const childCheckboxes =
group.querySelectorAll<HTMLInputElement>(
'input[name="SelectedCompetencyIds"]',
);

const updateState = () => {
const isChecked = groupToggle.checked;
if (!groupToggle) {
return;
}

childCheckboxes.forEach((_, index) => {
childCheckboxes[index].checked = isChecked;
const setChildrenCheckedState = (checked: boolean) => {
childCheckboxes.forEach((checkboxElement) => {
const checkbox = checkboxElement;
checkbox.checked = checked;
});
};

// Run when the group checkbox changes
groupToggle.addEventListener('change', updateState);
if (groupToggle.checked) {
setChildrenCheckedState(true);
}

// Also run at page load in case some are pre-checked server-side
updateState();
groupToggle.addEventListener('change', () => {
setChildrenCheckedState(groupToggle.checked);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@
@foreach (var competency in competencyGroup)
{
<div class="nhsuk-checkboxes__item">
<input class="nhsuk-checkboxes__input" data-group="@competencyGroup.Key" id="competency-check-@competency.StructureId" name="SelectedCompetencyIds" checked="@(Model.SelectedCompetencyIds != null ? Model.SelectedCompetencyIds.Contains((int)competency.CompetencyID) : false)" type="checkbox" value="@competency.StructureId">
<input class="nhsuk-checkboxes__input"
data-group="@competencyGroup.Key"
id="competency-check-@competency.StructureId"
name="SelectedCompetencyIds"
checked="@(competencyGroup.Any(x => x.GroupOptionalCompetencies) || competency.Optional ? "checked" : null)"type="checkbox" value="@competency.StructureId">
<label class="nhsuk-label nhsuk-checkboxes__label" for="competency-check-@competency.StructureId">
@foreach (var flag in competency.CompetencyFlags)
{
Expand Down
Loading