diff --git a/projects/ng-otp-input/src/lib/components/ng-otp-input/ng-otp-input.component.ts b/projects/ng-otp-input/src/lib/components/ng-otp-input/ng-otp-input.component.ts index 8338478..fedb5b5 100644 --- a/projects/ng-otp-input/src/lib/components/ng-otp-input/ng-otp-input.component.ts +++ b/projects/ng-otp-input/src/lib/components/ng-otp-input/ng-otp-input.component.ts @@ -142,7 +142,15 @@ export class NgOtpInputComponent implements OnInit, AfterViewInit, OnDestroy, Co onKeyDown($event, inputIdx) { const prevInputId = this.getBoxId(inputIdx - 1); const currentInputId = this.getBoxId(inputIdx); - const nextInputId = this.getBoxId(inputIdx + 1); + if (KeyboardUtil.ifKey($event, 'Enter')) { + let inp = this.document.getElementById(currentInputId); + const form = inp?.closest('form'); + if (form) { + $event.preventDefault(); + form.dispatchEvent(new Event('submit')); + return; + } + } if (KeyboardUtil.ifSpacebar($event)) { $event.preventDefault(); return false;