From 6cd1baea985672d24d515c17f69ee2ea25edd026 Mon Sep 17 00:00:00 2001
From: EETagent
Date: Fri, 25 Nov 2022 16:24:03 +0100
Subject: [PATCH] feat: initial form validation PoC
---
frontend/src/routes/register/+page.svelte | 271 ++++++++++++++++++----
1 file changed, 226 insertions(+), 45 deletions(-)
diff --git a/frontend/src/routes/register/+page.svelte b/frontend/src/routes/register/+page.svelte
index eaa2711..6607990 100644
--- a/frontend/src/routes/register/+page.svelte
+++ b/frontend/src/routes/register/+page.svelte
@@ -8,6 +8,9 @@
import SplitLayout from '$lib/components/layout/SplitLayout.svelte';
import TextField from '$lib/components/textfield/TextField.svelte';
+ import { createForm } from 'svelte-forms-lib';
+ import * as yup from 'yup';
+
let applicationValue = '';
const redirectToCode = () => {
@@ -18,7 +21,47 @@
};
const pageCount = 3;
- let pageIndex = 0;
+ let pageIndex = 3;
+
+ const formInitialValues = {
+ name: '',
+ email: '',
+ telephone: '',
+ birthSurname: '',
+ birthPlace: '',
+ birthDate: '',
+ sex: '',
+ home: '',
+ parentEmail: '',
+ parentTelephone: '',
+ citizenship: '',
+ personalId: '',
+ study: '',
+ applicationId: ''
+ };
+
+ const { form, errors, state, handleChange, handleSubmit } = createForm({
+ initialValues: formInitialValues,
+ validationSchema: yup.object().shape({
+ name: yup.string().required(),
+ email: yup.string().email().required(),
+ telephone: yup.string().required(),
+ birthSurname: yup.string().required(),
+ birthPlace: yup.string().required(),
+ birthDate: yup.string().required(),
+ sex: yup.string().required(),
+ home: yup.string().required(),
+ parentEmail: yup.string().email().required(),
+ parentTelephone: yup.string().required(),
+ citizenship: yup.string().required(),
+ personalId: yup.string().required(),
+ study: yup.string().required(),
+ applicationId: yup.string().required()
+ }),
+ onSubmit: (values) => {
+ alert(JSON.stringify(values));
+ }
+ });
@@ -29,25 +72,52 @@
{#if pageIndex === 0}
- Registrace
-
- Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Fusce suscipit libero eget elit.
-
-
-
+
{/if}
{#if pageIndex === 1}
Něco o tobě
@@ -55,17 +125,46 @@
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Fusce suscipit libero eget elit.
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
{/if}
{#if pageIndex === 2}
@@ -74,9 +173,33 @@
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Fusce suscipit libero eget elit.
-
-
-
+
+
+
+
+
+
+
+
+
{/if}
{#if pageIndex === 3}
@@ -85,25 +208,78 @@
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Fusce suscipit libero eget elit.
-
-
-
+
+
+
-
-
+
+
{/if}
{
- if (pageIndex === pageCount) {
- //TODO: Submit
- } else {
- pageIndex++;
+ on:click={async (e) => {
+ 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;
}
+
+ 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"
type="submit"
@@ -124,6 +300,11 @@
@apply mx-auto w-[90%] h-full;
@apply items-center justify-center;
}
+ .form > form {
+ @apply flex flex-col;
+ @apply w-full;
+ @apply items-center justify-center;
+ }
.dotActive {
@apply bg-sspsBlue;
}