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

Fixed #15200 - backspace key doesn't work @ Template #15203

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
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
17 changes: 8 additions & 9 deletions src/app/components/inputotp/inputotp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,43 +265,42 @@ export class InputOtp implements AfterContentInit {
}

onKeyDown(event) {
const keyCode = event.keyCode;

switch (keyCode) {
case 37:
switch (event.code) {
case 'ArrowLeft':
this.moveToPrev(event);
event.preventDefault();

break;

case 38:
case 40:
case 'ArrowUp':
case 'ArrowDown':
event.preventDefault();

break;

case 8:
case 'Backspace':
if (event.target.value.length === 0) {
this.moveToPrev(event);
event.preventDefault();
}

break;

case 39:
case 'ArrowRight':
this.moveToNext(event);
event.preventDefault();

break;

default:
if (this.integerOnly && !((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105))) {
if ((this.integerOnly && !((event.code.startsWith('Digit') || event.code.startsWith('Numpad')) && Number(event.key) >= 0 && Number(event.key) <= 9)) || (this.tokens.join('').length >= this.length && event.code !== 'Delete')) {
event.preventDefault();
}

break;
}
}

onPaste(event) {
let paste = event.clipboardData.getData('text');

Expand Down
6 changes: 3 additions & 3 deletions src/app/showcase/doc/inputotp/sampledoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Code } from '../../domain/code';
<p class="text-color-secondary block mb-5">Please enter the code sent to your phone.</p>
<p-inputOtp [(ngModel)]="value" [length]="6" style="gap: 0">
<ng-template pTemplate="input" let-token let-events="events" let-index="index">
<input pInputText type="text" [maxLength]="1" (input)="events.input($event)" [attr.value]="token" class="custom-otp-input" />
<input pInputText type="text" [maxLength]="1" (input)="events.input($event)" (keydown)="events.keydown($event)" [attr.value]="token" class="custom-otp-input" />
<div *ngIf="index === 3" class="px-3">
<i class="pi pi-minus"></i>
</div>
Expand Down Expand Up @@ -76,7 +76,7 @@ export class SampleDoc {
<p class="text-color-secondary block mb-5">Please enter the code sent to your phone.</p>
<p-inputOtp [(ngModel)]="value" [length]="6" style="gap: 0">
<ng-template pTemplate="input" let-token let-events="events" let-index="index">
<input pInputText type="text" [maxLength]="1" (input)="events.input($event)" [attr.value]="token" class="custom-otp-input" />
<input pInputText type="text" [maxLength]="1" (input)="events.input($event)" (keydown)="events.keydown($event)" [attr.value]="token" class="custom-otp-input" />
<div *ngIf="index === 3" class="px-3">
<i class="pi pi-minus"></i>
</div>
Expand All @@ -94,7 +94,7 @@ export class SampleDoc {
<p class="text-color-secondary block mb-5">Please enter the code sent to your phone.</p>
<p-inputOtp [(ngModel)]="value" [length]="6" style="gap: 0">
<ng-template pTemplate="input" let-token let-events="events" let-index="index">
<input pInputText type="text" [maxLength]="1" (input)="events.input($event)" [attr.value]="token" class="custom-otp-input" />
<input pInputText type="text" [maxLength]="1" (input)="events.input($event)" (keydown)="events.keydown($event)" [attr.value]="token" class="custom-otp-input" />
<div *ngIf="index === 3" class="px-3">
<i class="pi pi-minus"></i>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/app/showcase/doc/inputotp/templatedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Code } from '../../domain/code';
<div class="card flex justify-content-center">
<p-inputOtp [(ngModel)]="value">
<ng-template pTemplate="input" let-token let-events="events">
<input pInputText class="custom-otp-input" (input)="events.input($event)" type="text" [attr.value]="token" [maxLength]="1" />
<input pInputText class="custom-otp-input" (keydown)="events.keydown($event)" (input)="events.input($event)" type="text" [attr.value]="token" [maxLength]="1" />
</ng-template>
</p-inputOtp>
</div>
Expand Down Expand Up @@ -45,14 +45,14 @@ export class TemplateDoc {
code: Code = {
basic: `<p-inputOtp [(ngModel)]="value">
<ng-template pTemplate="input" let-token let-events="events">
<input pInputText class="custom-otp-input" (input)="events.input($event)" type="text" [attr.value]="token" [maxLength]="1" />
<input pInputText class="custom-otp-input" (input)="events.input($event)" (keydown)="events.keydown($event)" type="text" [attr.value]="token" [maxLength]="1" />
</ng-template>
</p-inputOtp>`,

html: `<div class="card flex justify-content-center">
<p-inputOtp [(ngModel)]="value">
<ng-template pTemplate="input" let-token let-events="events">
<input pInputText class="custom-otp-input" (input)="events.input($event)" type="text" [attr.value]="token" [maxLength]="1" />
<input pInputText class="custom-otp-input" (input)="events.input($event)" (keydown)="events.keydown($event)" type="text" [attr.value]="token" [maxLength]="1" />
</ng-template>
</p-inputOtp>
</div>`,
Expand Down
Loading