mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-20 07:10:02 +00:00
fix otp code paste in mobile browsers (#6197)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
parent
623649f6d9
commit
febefacef9
@ -31,7 +31,6 @@
|
|||||||
on:change
|
on:change
|
||||||
on:keyup
|
on:keyup
|
||||||
on:input
|
on:input
|
||||||
maxlength={1}
|
|
||||||
inputmode="numeric"
|
inputmode="numeric"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
placeholder=""
|
placeholder=""
|
||||||
|
@ -81,9 +81,14 @@
|
|||||||
|
|
||||||
if (value == null || value === '') return
|
if (value == null || value === '') return
|
||||||
|
|
||||||
|
if (value.length === fields.length) {
|
||||||
|
pasteOtpCode(value)
|
||||||
|
} else {
|
||||||
const index = fields.findIndex(({ id }) => id === target.id)
|
const index = fields.findIndex(({ id }) => id === target.id)
|
||||||
if (index === -1) return
|
if (index === -1) return
|
||||||
|
|
||||||
|
target.value = value[0]
|
||||||
|
|
||||||
if (Object.values(otpData).every((v) => v !== '')) {
|
if (Object.values(otpData).every((v) => v !== '')) {
|
||||||
void validateOtp()
|
void validateOtp()
|
||||||
return
|
return
|
||||||
@ -97,6 +102,7 @@
|
|||||||
nextInput.focus()
|
nextInput.focus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function clearOtpData (): void {
|
function clearOtpData (): void {
|
||||||
Object.keys(otpData).forEach((key) => {
|
Object.keys(otpData).forEach((key) => {
|
||||||
@ -139,9 +145,15 @@
|
|||||||
if (e.clipboardData == null) return
|
if (e.clipboardData == null) return
|
||||||
|
|
||||||
const text = e.clipboardData.getData('text')
|
const text = e.clipboardData.getData('text')
|
||||||
|
pasteOtpCode(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
function pasteOtpCode (text: string): boolean {
|
||||||
const digits = text.split('').filter((it) => it !== ' ')
|
const digits = text.split('').filter((it) => it !== ' ')
|
||||||
|
|
||||||
if (digits.length !== fields.length) return
|
if (digits.length !== fields.length) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
let focusName: string | undefined = undefined
|
let focusName: string | undefined = undefined
|
||||||
|
|
||||||
@ -160,6 +172,8 @@
|
|||||||
if (Object.values(otpData).every((v) => v !== '')) {
|
if (Object.values(otpData).every((v) => v !== '')) {
|
||||||
void validateOtp()
|
void validateOtp()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
$: if (formElement != null) {
|
$: if (formElement != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user