Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(keyfilter): regex test with the correct value onKeyPress #16085

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not verified this but should lines 234 and 235
|| 0
be replaced with
|| Number.MAX_SAFE_INTEGER


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

Expand Down
Loading