From 12438eeff6fce2faab244e47708dfd0f3a9731b0 Mon Sep 17 00:00:00 2001 From: Jackson Bush Date: Fri, 12 May 2023 14:07:14 -0400 Subject: [PATCH] Fix for errors thrown when the setTimeout queued in bindListeners() ends up running after the popup has been closed, and the confirmation on the confirmpopup component has already been set to null. Added null checks to the confirmation property. Fixes #13034 --- .../components/confirmpopup/confirmpopup.ts | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/app/components/confirmpopup/confirmpopup.ts b/src/app/components/confirmpopup/confirmpopup.ts index 821707d0911..03a6aa3cfe4 100755 --- a/src/app/components/confirmpopup/confirmpopup.ts +++ b/src/app/components/confirmpopup/confirmpopup.ts @@ -21,8 +21,8 @@ import { DomHandler, ConnectedOverlayScrollHandler } from 'primeng/dom'; (@animation.done)="onAnimationEnd($event)" >
- - {{ confirmation.message }} + + {{ confirmation?.message }}
@@ -236,7 +236,7 @@ export class ConfirmPopup implements AfterContentInit, OnDestroy { } accept() { - if (this.confirmation.acceptEvent) { + if (this.confirmation?.acceptEvent) { this.confirmation.acceptEvent.emit(); } @@ -244,7 +244,7 @@ export class ConfirmPopup implements AfterContentInit, OnDestroy { } reject() { - if (this.confirmation.rejectEvent) { + if (this.confirmation?.rejectEvent) { this.confirmation.rejectEvent.emit(); } @@ -283,9 +283,11 @@ export class ConfirmPopup implements AfterContentInit, OnDestroy { const documentTarget: any = this.el ? this.el.nativeElement.ownerDocument : this.document; this.documentClickListener = this.renderer.listen(documentTarget, documentEvent, (event) => { - let targetElement = this.confirmation.target; - if (this.container !== event.target && !this.container.contains(event.target) && targetElement !== event.target && !targetElement.contains(event.target)) { - this.hide(); + if (this.confirmation) { + let targetElement = this.confirmation.target; + if (this.container !== event.target && !this.container.contains(event.target) && targetElement !== event.target && !targetElement.contains(event.target)) { + this.hide(); + } } }); } @@ -319,7 +321,7 @@ export class ConfirmPopup implements AfterContentInit, OnDestroy { bindScrollListener() { if (!this.scrollHandler) { - this.scrollHandler = new ConnectedOverlayScrollHandler(this.confirmation.target, () => { + this.scrollHandler = new ConnectedOverlayScrollHandler(this.confirmation?.target, () => { if (this.visible) { this.hide(); } @@ -368,11 +370,11 @@ export class ConfirmPopup implements AfterContentInit, OnDestroy { } get acceptButtonLabel(): string { - return this.confirmation.acceptLabel || this.config.getTranslation(TranslationKeys.ACCEPT); + return this.confirmation?.acceptLabel || this.config.getTranslation(TranslationKeys.ACCEPT); } get rejectButtonLabel(): string { - return this.confirmation.rejectLabel || this.config.getTranslation(TranslationKeys.REJECT); + return this.confirmation?.rejectLabel || this.config.getTranslation(TranslationKeys.REJECT); } ngOnDestroy() {