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

Allow only digits on the OTP fields #763

Merged
merged 1 commit into from
Feb 14, 2025
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
2 changes: 1 addition & 1 deletion webapp/public/locale/en/out/strings.out.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions webapp/public/locale/en/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@
"utilities_title": "Green Energy"
},
"otp": {
"code_resent": "New code sent to {{ phone }}.",
"code_resent": "New code sent to {{phone}}.",
"did_not_receive": "Didn't recieve a text message?",
"enter_code": "Enter code ",
"enter_code": "Enter code {{index}}",
"enter_code_sent_to": "Enter the code that we sent to",
"send_new_code": "Send a new code",
"verify": "Verify",
Expand Down
2 changes: 1 addition & 1 deletion webapp/public/locale/es/out/strings.out.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion webapp/public/locale/es/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@
"otp": {
"code_resent": "Nuevo código enviado a {{phone}}.",
"did_not_receive": "¿No recibiste un mensaje de texto?",
"enter_code": "Introduzca el código",
"enter_code": "Introduzca código {{index}}",
"enter_code_sent_to": "Introducir el código que enviamos",
"send_new_code": "Enviar un nuevo código",
"verify": "Verificar",
Expand Down
8 changes: 5 additions & 3 deletions webapp/src/pages/OneTimePassword.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const OneTimePassword = () => {

const onlyDigits = /^\d+$/.test(value);
if (!onlyDigits) {
// Reset any non-digits to previous value
setOtpChars(setCharAt(otpChars, otpChars[index], index));
return;
}

Expand Down Expand Up @@ -160,7 +162,7 @@ const OneTimePassword = () => {
{otpChars.map((data, index) => (
<input
className="otp-field mb-2 p-1"
type="text"
type="numbers"
name="otp"
// Must use the OTP length here, so any input can capture the full paste.
maxLength={OTP_LENGTH}
Expand All @@ -169,11 +171,11 @@ const OneTimePassword = () => {
value={data}
placeholder="&middot;"
onInput={(e) => handleOtpChange(e, index)}
onPaste={handleOtpPaste}
onKeyDown={(e) => handleOtpKeyDown(e, index)}
onPaste={handleOtpPaste}
onFocus={(e) => e.target.select()}
autoFocus={index === 0}
aria-label={t("otp:enter_code") + (index + 1)}
aria-label={t("otp:enter_code", { index: index + 1 })}
autoComplete="one-time-code"
/>
))}
Expand Down
Loading