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 cbd1c08..b4fe068 100644 --- a/frontend/src/routes/(candidate)/auth/login/[code=application]/+page.svelte +++ b/frontend/src/routes/(candidate)/auth/login/[code=application]/+page.svelte @@ -6,14 +6,12 @@ import { page } from '$app/stores'; import { goto } from '$app/navigation'; import { apiLogin } from '$lib/@api/candidate'; - - + let applicationId = Number($page.params.code); let codeValueMobile: string = ''; let codeValueArray: Array = []; let codeElementArray: Array = []; - $: { codeValueMobile = codeValueMobile.toUpperCase(); codeValueArray = codeValueMobile.split(''); @@ -35,25 +33,41 @@ codeElementArray[index + 1].focus(); } } - codeValueMobile = codeValueArray.join('') + codeValueMobile = codeValueArray.join(''); }; - + $: if (codeValueArray.length === 8) { submit(); - }; + } async function submit() { try { - await apiLogin({applicationId, password: codeValueMobile}); - goto("/dashboard"); - } catch (e) { + await apiLogin({ applicationId, password: codeValueMobile }); + goto('/dashboard'); + } catch (e) { console.error(e); } // alert('ApplicationId: ' + applicationId + '; Password: ' + codeValueMobile); } + const onPaste = (e: ClipboardEvent) => { + e.preventDefault(); + const text = e.clipboardData?.getData('text/plain'); + if (text) { + codeValueMobile = text; + } + for (const el of codeElementArray) { + el.blur(); + } + }; + onMount(() => { codeElementArray[0].focus(); + + // Document on:paste + document.onpaste = (e: ClipboardEvent) => { + onPaste(e); + }; }); @@ -61,18 +75,14 @@