further cleaning up

This commit is contained in:
Samuel Andert 2023-08-08 07:19:43 +02:00
parent 1ad46b3252
commit 6d696eb4cc
5 changed files with 18 additions and 21 deletions

View File

@ -55,7 +55,6 @@
"@sveltejs/vite-plugin-svelte": "^2.4.3", "@sveltejs/vite-plugin-svelte": "^2.4.3",
"@wagmi/core": "^1.3.8", "@wagmi/core": "^1.3.8",
"@xstate/svelte": "^2.1.0", "@xstate/svelte": "^2.1.0",
"chokidar": "^3.5.3",
"viem": "^1.4.2", "viem": "^1.4.2",
"xstate": "^4.38.2" "xstate": "^4.38.2"
} }

View File

@ -15,7 +15,6 @@
%sveltekit.head% %sveltekit.head%
</head> </head>
<script> <script>
// Fix `global is not defined` error
global = window; global = window;
window.process = { window.process = {
env: { env: {

View File

@ -50,7 +50,7 @@
<div class="input-group input-group-divider grid-cols-[auto_1fr_auto] rounded-container-token h-14"> <div class="input-group input-group-divider grid-cols-[auto_1fr_auto] rounded-container-token h-14">
<button class="input-group-shim" on:drawer{closeDrawer} on:click={openDrawer}> <button class="input-group-shim" on:drawer{closeDrawer} on:click={openDrawer}>
<Avatar src="logo.png" width="w-10" rounded="rounded-full" /> <Avatar src="/logo.png" width="w-10" rounded="rounded-full" />
</button> </button>
<input <input

View File

@ -1,28 +1,19 @@
<script lang="ts"> <script lang="ts">
import { superForm } from 'sveltekit-superforms/client'; import { superForm } from 'sveltekit-superforms/client';
import { UserSchema } from '$lib/types/UserSchema';
import { afterUpdate } from 'svelte'; import { afterUpdate } from 'svelte';
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
import { RangeSlider, SlideToggle } from '@skeletonlabs/skeleton'; import { RangeSlider, SlideToggle } from '@skeletonlabs/skeleton';
export let me; export let me;
const initialFormData = { const { initialFormData, fields, validators } = $me.context;
name: '',
email: '',
about: '',
age: '',
favoriteFood: ''
};
const fields = ['name', 'email', 'about', 'age', 'favoriteFood'];
const { form, errors, validate, constraints } = superForm(initialFormData, { const { form, errors, validate, constraints } = superForm(initialFormData, {
validators: UserSchema, validators: validators,
warnings: { warnings: {
noValidationAndConstraints: false noValidationAndConstraints: false
}, },
validationMethod: 'oninput', // Trigger validation on input events validationMethod: 'oninput',
clearOnSubmit: 'errors-and-message' clearOnSubmit: 'errors-and-message'
}); });
@ -69,9 +60,12 @@
}); });
</script> </script>
<div class="w-full p-6 border-2 border-red-500"> <div class="p-6">
My ID is: {$me.id} <br /> My ID is: {$me.id} <br />
My state is: {$me.state} My state is: {$me.state}
</div>
<div class="flex items-center justify-center w-full h-full p-6">
{#if $successMessage} {#if $successMessage}
<aside class="w-full max-w-md p-4 alert variant-ghost" id="message-container"> <aside class="w-full max-w-md p-4 alert variant-ghost" id="message-container">
<div class="alert-message"> <div class="alert-message">

View File

@ -1,5 +1,6 @@
<script lang="ts"> <script lang="ts">
import Composer from '$lib/core/Composer.svelte'; import Composer from '$lib/core/Composer.svelte';
import { UserSchema } from '$lib/types/UserSchema';
let composer = { let composer = {
id: 'FormContainer', id: 'FormContainer',
@ -19,7 +20,15 @@
id: 'validation', id: 'validation',
initial: 'notValidated', initial: 'notValidated',
context: { context: {
isValidated: false initialFormData: {
name: '',
email: '',
about: '',
age: '',
favoriteFood: ''
},
fields: ['name', 'email', 'about', 'age', 'favoriteFood'],
validators: UserSchema
}, },
states: { states: {
notValidated: { notValidated: {
@ -38,10 +47,6 @@
} }
} }
} }
},
services: {
setValidated: (context) => (context.isValidated = true),
setNotValidated: (context) => (context.isValidated = false)
} }
} }
}, },