From b00a21b3d69acd7c1bbc2456fd3e977621c532d3 Mon Sep 17 00:00:00 2001 From: Austin Walker Date: Tue, 23 Jul 2024 12:41:17 -0600 Subject: [PATCH] fix(keyfilter): regex test with the correct value onKeyPress --- src/app/components/keyfilter/keyfilter.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/app/components/keyfilter/keyfilter.ts b/src/app/components/keyfilter/keyfilter.ts index 05ef4efeb16..89206a8f026 100755 --- a/src/app/components/keyfilter/keyfilter.ts +++ b/src/app/components/keyfilter/keyfilter.ts @@ -113,7 +113,11 @@ export class KeyFilter implements Validator { lastValue: any; - constructor(@Inject(DOCUMENT) private document: Document, @Inject(PLATFORM_ID) private platformId: any, public el: ElementRef) { + constructor( + @Inject(DOCUMENT) private document: Document, + @Inject(PLATFORM_ID) private platformId: any, + public el: ElementRef + ) { if (isPlatformBrowser(this.platformId)) { this.isAndroid = DomHandler.isAndroid(); } else { @@ -227,8 +231,9 @@ export class KeyFilter implements Validator { } let valueCheck = this.el.nativeElement.value || ''; - - let val = valueCheck + cc; + const selectionStart = (e.currentTarget).selectionStart || 0; + const selectionEnd = (e.currentTarget).selectionEnd || 0; + let val = valueCheck.substring(0, selectionStart) + cc + valueCheck.substring(selectionEnd); ok = (this.regex).test(val);