diff --git a/frontend/src/lib/components/textfield/TextField.svelte b/frontend/src/lib/components/textfield/TextField.svelte index 526ef8a..19ddf61 100644 --- a/frontend/src/lib/components/textfield/TextField.svelte +++ b/frontend/src/lib/components/textfield/TextField.svelte @@ -1,11 +1,27 @@ diff --git a/frontend/src/routes/login/[code=application]/+page.svelte b/frontend/src/routes/login/[code=application]/+page.svelte index 7067934..d3a9d96 100644 --- a/frontend/src/routes/login/[code=application]/+page.svelte +++ b/frontend/src/routes/login/[code=application]/+page.svelte @@ -3,21 +3,20 @@ import woman from '$lib/assets/woman.png'; import { onMount } from 'svelte'; - + import { page } from '$app/stores'; + + + let applicationId = Number($page.params.code); let codeValueMobile: string = ''; let codeValueArray: Array = []; let codeElementArray: Array = []; - const inputMobileOnKeyUp = (event: KeyboardEvent) => { - let input = event.target as HTMLInputElement; - if (input.value.length > 8) { - input.value = input.value.slice(0, 8); - } - let splittedInput = input.value.split(''); - - codeValueArray = splittedInput; - }; + $: { + codeValueMobile = codeValueMobile.toUpperCase(); + codeValueArray = codeValueMobile.split(''); + console.log(codeValueArray); + } const inputDesktopOnKeyDown = (index: number, e: KeyboardEvent) => { if (e.key === 'Backspace') { @@ -29,12 +28,16 @@ if (e.key.length > 1) { return; } - codeValueArray[index] = e.key; + codeValueArray[index] = e.key.toUpperCase(); if (codeElementArray[index + 1]) { codeElementArray[index + 1].focus(); } } - codeValueMobile = codeValueArray.join(''); + codeValueMobile = codeValueArray.join('') + }; + + $: if (codeValueArray.length === 8) { + alert('ApplicationId: ' + applicationId + '; Password: ' + codeValueMobile); }; onMount(() => { @@ -50,7 +53,7 @@ bind:value={codeValueMobile} type="text" class="codeInputMobile" - on:keyup={inputMobileOnKeyUp} + /> {#each [1, 2, 3, 4] as value} { - // TODO: Validation - if (applicationValue) { - goto(`/login/${applicationValue}`); - } - }; - const pageCount = 3; let pageIndex = 0; + let pagesFilled = 0; const formInitialValues = { name: '', @@ -31,7 +25,7 @@ birthPlace: '', birthDate: '', sex: '', - home: '', + address: '', parentEmail: '', parentTelephone: '', citizenship: '', @@ -45,12 +39,12 @@ validationSchema: yup.object().shape({ name: yup.string().required(), email: yup.string().email().required(), - telephone: yup.string().required(), + telephone: yup.string().required().matches(/^\+\d{1,3} \d{3} \d{3} \d{3}$/), birthSurname: yup.string().required(), birthPlace: yup.string().required(), birthDate: yup.string().required(), sex: yup.string().required(), - home: yup.string().required(), + address: yup.string().required(), parentEmail: yup.string().email().required(), parentTelephone: yup.string().required(), citizenship: yup.string().required(), @@ -62,6 +56,40 @@ alert(JSON.stringify(values)); } }); + + const isPageInvalid = (): boolean => { + switch (pageIndex) { + case 0: + if ($errors.name || $errors.email || $errors.telephone) { + return true; + } + break; + + case 1: + if ($errors.birthSurname || $errors.birthPlace || $errors.birthDate || $errors.sex) { + return true; + } + break; + case 2: + if ($errors.address || $errors.parentEmail || $errors.parentTelephone) { + return true; + } + break; + case 3: + if ( + $errors.citizenship || + $errors.personalId || + $errors.study || + $errors.applicationId + ) { + return true; + } + break; + default: + return false; + } + return false; + } @@ -109,6 +137,7 @@ on:change={handleChange} bind:value={$form.telephone} type="tel" + format="tel" placeholder="Telefon" icon > @@ -156,6 +185,7 @@ on:change={handleChange} bind:value={$form.birthDate} type="text" + format="birthdate" placeholder="Datum narození" /> @@ -224,6 +254,7 @@ on:change={handleChange} bind:value={$form.personalId} type="text" + format="personalIdNumber" placeholder="Rodné číslo" /> { await handleSubmit(e); - switch (pageIndex) { - case 0: - if ($errors.name || $errors.email || $errors.telephone) { - return; - } - break; - - case 1: - if ($errors.birthSurname || $errors.birthPlace || $errors.birthDate || $errors.sex) { - return; - } - break; - case 2: - if ($errors.home || $errors.parentEmail || $errors.parentTelephone) { - return; - } - break; - case 3: - if ( - $errors.citizenship || - $errors.personalId || - $errors.study || - $errors.applicationId - ) { - return; - } - break; - default: - break; + if (isPageInvalid()) return; + if (pageIndex === pageCount) { + alert('should submit'); + } else { + pagesFilled++; + pageIndex++; } - - pageIndex++; errors.set(formInitialValues); }} - class="w-full mt-8 md:w-3/5 p-3 rounded-lg font-semibold text-xl transition-colors duration-300 bg-sspsBlue hover:bg-sspsBlueDark text-white" + class="w-full mt-8 md:w-3/5 p-3 rounded-lg font-semibold text-xl transition-colors duration-300 bg-sspsBlue hover:bg-sspsBlueDark text-white hover:cursor-pointer" type="submit" value={pageIndex === pageCount ? 'Odeslat' : 'Pokračovat'} />
{#each Array(pageCount + 1) as _, i} - +
@@ -305,6 +322,11 @@ @apply w-full; @apply items-center justify-center; } + .dot { + @apply ml-2 w-4 h-4 + @apply hover:cursor-pointer hover:bg-sspsBlue + @apply rounded-full bg-sspsGray; + } .dotActive { @apply bg-sspsBlue; }