diff --git a/frontend/src/routes/(candidate)/auth/login/[code=application]/+page.svelte b/frontend/src/routes/(candidate)/auth/login/[code=application]/+page.svelte index 128517e..6bb43cc 100644 --- a/frontend/src/routes/(candidate)/auth/login/[code=application]/+page.svelte +++ b/frontend/src/routes/(candidate)/auth/login/[code=application]/+page.svelte @@ -15,34 +15,34 @@ let isError: boolean = false; $: { + codeValueMobile = codeValueMobile.slice(0, 12); codeValueMobile = codeValueMobile.toUpperCase(); codeValueArray = codeValueMobile.split(''); - console.log(codeValueArray); } const inputDesktopOnKeyDown = async (index: number, e: KeyboardEvent) => { if (e.key === 'Backspace') { + e.preventDefault(); codeValueArray[index] = ''; - if (codeElementArray[index - 1]) { - codeElementArray[index - 1].focus(); - } + const prevElement = codeElementArray[index - 1]; + if (prevElement) codeElementArray[index - 1].focus(); } else { - if (e.key.length > 1) { - return; - } + if (e.key.length > 1 || e.metaKey || e.ctrlKey) return; + e.preventDefault(); codeValueArray[index] = e.key.toUpperCase(); - if (codeElementArray[index + 1]) { - codeElementArray[index + 1].focus(); - } + const nextElement = codeElementArray[index + 1]; + if (nextElement) codeElementArray[index + 1].focus(); } codeValueMobile = codeValueArray.join(''); + }; - if (codeValueArray.filter((item) => item !== '').length === 12) { - await submit(); + $: { + if (codeValueMobile.length === 12) { + submit(); } else { isError = false; } - }; + } const submit = async () => { console.log('submitting: ', codeValueArray); @@ -65,16 +65,10 @@ const onPaste = async (e: ClipboardEvent) => { e.preventDefault(); const text = e.clipboardData?.getData('text/plain').slice(0, 12); - if (text) { - codeValueMobile = text; - codeValueArray = text.split(''); - } + if (text) codeValueMobile = text; for (const el of codeElementArray) { el.blur(); } - if (codeValueArray.filter((item) => item !== '').length === 12) { - await submit(); - } }; onMount(() => { @@ -92,7 +86,7 @@