Skip to content

Commit

Permalink
fix(keyfilter): regex test with the correct value onKeyPress
Browse files Browse the repository at this point in the history
  • Loading branch information
BGBRWR committed Jul 23, 2024
1 parent 98f9682 commit b00a21b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/app/components/keyfilter/keyfilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -227,8 +231,9 @@ export class KeyFilter implements Validator {
}

let valueCheck = this.el.nativeElement.value || '';

let val = valueCheck + cc;
const selectionStart = (<HTMLInputElement>e.currentTarget).selectionStart || 0;
const selectionEnd = (<HTMLInputElement>e.currentTarget).selectionEnd || 0;
let val = valueCheck.substring(0, selectionStart) + cc + valueCheck.substring(selectionEnd);

ok = (<RegExp>this.regex).test(val);

Expand Down

0 comments on commit b00a21b

Please sign in to comment.