fix(otp): pegar código completo distribuye dígitos en todos los campos
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
34004b4d98
commit
e1ba78edb8
+14
-2
@@ -424,7 +424,17 @@ let _reenvioTimer = null;
|
||||
// ── OTP input navegación automática ──────────────────────────────────
|
||||
document.querySelectorAll('.otp-digit').forEach((inp, i, arr) => {
|
||||
inp.addEventListener('input', () => {
|
||||
inp.value = inp.value.replace(/\D/g, '').slice(-1);
|
||||
const val = inp.value.replace(/\D/g, '');
|
||||
if (val.length > 1) {
|
||||
// Pega múltiples dígitos (mobile/autofill)
|
||||
const digits = val.slice(0, 6);
|
||||
arr.forEach((d, j) => { d.value = digits[j] || ''; });
|
||||
const last = Math.min(digits.length - 1, arr.length - 1);
|
||||
arr[last].focus();
|
||||
if (otpCompleto()) verificarOtp();
|
||||
return;
|
||||
}
|
||||
inp.value = val;
|
||||
if (inp.value && i < arr.length - 1) arr[i + 1].focus();
|
||||
if (otpCompleto()) verificarOtp();
|
||||
});
|
||||
@@ -435,7 +445,9 @@ document.querySelectorAll('.otp-digit').forEach((inp, i, arr) => {
|
||||
e.preventDefault();
|
||||
const txt = (e.clipboardData || window.clipboardData).getData('text').replace(/\D/g,'').slice(0,6);
|
||||
arr.forEach((d, j) => { d.value = txt[j] || ''; });
|
||||
if (txt.length === 6) { arr[5].focus(); verificarOtp(); }
|
||||
const last = Math.min(txt.length - 1, arr.length - 1);
|
||||
if (last >= 0) arr[last].focus();
|
||||
if (txt.length === 6) verificarOtp();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user