0:
CategoryId: "31b7a227-9fda-4d14-8e1f-1dee5beeccb4"
Code: "GMA0300"
Description: "PA-5215: Renamed"
Enabled: true
Favorite: false
Id: "26cfdb68-ef69-4df0-b4dc-5b9c6501b0dd"
InstrumentType: null
Moniker: "1GMA0300"
Name: "Celiac Disease Panel (tTG IgG, tTG IgA, DGP IgG)"
Tests: Array(3)
0:
Code: "GMA0304"
Id: "e2bb4607-c227-4483-a3e9-55c1bc5a6781"
Name: "Deamidated Gliadin Peptide (DGP) IgG"
__proto__: Object
1: {Id: "2fcd610f-d453-4c4f-a8dc-1a5f50e88548", Code: "GMA0301", Name:
"Tissue Transglutaminase (tTG) IgA"}
2: {Id: "de41b236-4866-419a-a6f4-5f7c1440d30f", Code: "GMA0302", Name:
"Tissue Transglutaminase (tTG) IgG"}
length: 3
__proto__: Array(0)
TestsSelectable: false
Here we have an array named selectedPanels, which contains subarrays of objects. These subarrays are mapped into panels, each containing checkboxes and expandable rows for Tests, which are also arrays with checkboxes.
When the panel checkbox is selected, all child checkboxes within Tests are also selected, resulting in a total Tests length of 3. However, when each test checkbox is deselected, the Tests length should decrease. The issue arises when using splice, as it removes the entire row upon deselecting each test checkbox, including the parent panel checkbox. The desired behavior is to only reduce the array length when deselecting individual tests, without removing the entire row.
You can view an image illustrating this issue here.
HTML File:
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" [name]="panel.Id + '-' + panel.Moniker" [ngModel]="checkAllTestsSelected(panel)"
(ngModelChange)="onPanelCheckboxUpdate($event, panel)" [id]="panel.Id + '-' + panel.Moniker">
<span class="custom-control-indicator"></span>
</label>
</ng-template>
<ng-template ngbPanelContent>
<div class="individual-panel" *ngFor="let test of panel.Tests">
<span class="text-dimmed">{{test.Name}}</span>
<span *ngIf="panel.Name.includes('ENA') || panel.Name.includes('Celiac')">
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" [name]="test.Id + '-' + test.Code"
[ngModel]="testSelectionSession.SelectedPanelIds.indexOf(panel.Id) > -1 || testSelectionSession.SelectedPanelIds.indexOf(test.AssociatedPanel?.Id) > -1"
(ngModelChange)="onTestCheckboxUpdate($event, test, panel)" [id]="test.Id + '-' + test.Code">
<span class="custom-control-indicator"></span>
</label>
</span>
</div>
TS File:
checkAllTestsSelected(panel: TestOrderPanel) {
// Implement logic here
}
onPanelCheckboxUpdate($event: boolean, panel: TestOrderPanel) {
// Implement logic here
}
onTestCheckboxUpdate($event: boolean, test: TestOrderPanelTest, panel: TestOrderPanel) {
// Implement logic here
}
The array in question is stored in selectedPanels. Any insights on how to address this issue would be greatly appreciated. Can anyone offer assistance?