From d1b471757df7b53259f9f3fcb2b8a25d9dc9743e Mon Sep 17 00:00:00 2001 From: Vishesh Singh <67804974+visheshism@users.noreply.github.com> Date: Thu, 2 Mar 2023 06:05:05 +0530 Subject: [PATCH] fixed if idx-1 becomes -ve & timeout for last idx --- verify-account-ui/script.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/verify-account-ui/script.js b/verify-account-ui/script.js index 6df6bf0..740d101 100644 --- a/verify-account-ui/script.js +++ b/verify-account-ui/script.js @@ -4,11 +4,16 @@ codes[0].focus() codes.forEach((code, idx) => { code.addEventListener('keydown', (e) => { - if(e.key >= 0 && e.key <=9) { + if (e.key >= 0 && e.key <= 9) { codes[idx].value = '' - setTimeout(() => codes[idx + 1].focus(), 10) - } else if(e.key === 'Backspace') { - setTimeout(() => codes[idx - 1].focus(), 10) + if (idx !== codes.length - 1) { + setTimeout(() => codes[idx + 1].focus(), 10) + } + } else if (e.key === 'Backspace') { + if (!idx - 1 < 0) { + setTimeout(() => codes[idx - 1].focus(), 10) + } + } }) -}) \ No newline at end of file +})