From 59df5c3a53e9337e9250516afb0f4fe5b62a0c34 Mon Sep 17 00:00:00 2001 From: "jeevaramanthan.m" Date: Thu, 2 Nov 2023 11:24:15 +0530 Subject: [PATCH] OTP fix --- react/src/machine-coding/otp/App.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/react/src/machine-coding/otp/App.jsx b/react/src/machine-coding/otp/App.jsx index ac1558317..191a1b302 100644 --- a/react/src/machine-coding/otp/App.jsx +++ b/react/src/machine-coding/otp/App.jsx @@ -7,11 +7,11 @@ const App = () => { let otpinputref = useRef([]); const handleOtp = (e, index) => { - const numericValue = e.target.value.replace(/[^0-9]/g, ''); + const numericValue = e.target.value.replace(/\D/g, ''); const singleDigitValue = numericValue.slice(0, 1); let copyotpfields = [...otpfields]; copyotpfields[index] = singleDigitValue; - if (index < otpfields.length - 1) { + if (index < otpfields.length - 1 && singleDigitValue) { otpinputref.current[index + 1].focus(); } setOtpFields(copyotpfields); @@ -61,7 +61,7 @@ const App = () => { ref={(el) => (otpinputref.current[index] = el)} onChange={(e) => handleOtp(e, index)} value={otpfields[index]} - type="number" + type="text" /> ); })}