From 4cec872f233bf5073976fbfc8ef61483db950417 Mon Sep 17 00:00:00 2001 From: jitender Date: Wed, 21 May 2025 14:05:41 +0530 Subject: [PATCH] #131 --- .../components/ng-otp-input/ng-otp-input.component.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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;