From 7fed9c98754bb39bd8a8ac7744f66a047b0c66df Mon Sep 17 00:00:00 2001 From: gkbishnoi07 Date: Mon, 14 Sep 2026 09:28:50 +0000 Subject: [PATCH] fix(dispense): stop repeating the invalid beneficiary-id alert checkBeneficiary() runs on (keyup) and re-issued the lookup whenever the id length was 12. maxlength=12 blocks extra characters but keyup still fires, so each extra keypress re-hit the backend and opened a fresh blocking error alert (one OK per keystroke). track the last-checked id and skip re-querying an unchanged value; reset it when the id is cleared/shortened. --- .../medicine-dispense/medicine-dispense.component.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/app/app-modules/inventory/medicine-dispense/medicine-dispense.component.ts b/src/app/app-modules/inventory/medicine-dispense/medicine-dispense.component.ts index 4c72b46..70936d5 100644 --- a/src/app/app-modules/inventory/medicine-dispense/medicine-dispense.component.ts +++ b/src/app/app-modules/inventory/medicine-dispense/medicine-dispense.component.ts @@ -186,6 +186,7 @@ export class MedicineDispenseComponent implements OnInit, OnDestroy, DoCheck { beneficiaryDetail: any; beneficiaryVisitDetailList: any; recentBeneficaryVisit: any; + lastCheckedBeneficiaryId: string | null = null; checkBeneficiary() { if (this.beneficiaryDetailForm.controls['beneficiaryID'].value === null) { this.nullifyBeneficiaryDetails(); @@ -200,6 +201,14 @@ export class MedicineDispenseComponent implements OnInit, OnDestroy, DoCheck { if ( this.beneficiaryDetailForm.controls['beneficiaryID'].value.length === 12 ) { + const currentId = + this.beneficiaryDetailForm.controls['beneficiaryID'].value; + // (keyup) fires on every keypress even once maxlength holds the value at + // 12 chars, so skip re-querying (and re-alerting) an unchanged id. + if (currentId === this.lastCheckedBeneficiaryId) { + return; + } + this.lastCheckedBeneficiaryId = currentId; this.inventoryService .getBeneficaryVisitDetail({ providerServiceMapID: @@ -273,6 +282,7 @@ export class MedicineDispenseComponent implements OnInit, OnDestroy, DoCheck { } } nullifyBeneficiaryDetails() { + this.lastCheckedBeneficiaryId = null; this.beneficiaryDetailForm.patchValue({ medicineDispenseType: null, visitCode: null,