From 1f7fd8ab7a09a215d8c9ae49c4b6f7e7e4539482 Mon Sep 17 00:00:00 2001 From: Samuel Andert Date: Tue, 8 Aug 2023 08:30:44 +0200 Subject: [PATCH] Part1 of refactoring InputFields into their own components. --- .../components/refactor/ComposerForm.svelte | 76 +++++++++---------- .../refactor/inputfields/SelectInput.svelte | 35 +++++++++ .../refactor/inputfields/SliderInput.svelte | 31 ++++++++ .../refactor/inputfields/TextInput.svelte | 61 +++++++++++++++ .../refactor/inputfields/ToggleInput.svelte | 19 +++++ src/routes/composer/form/+page.svelte | 15 ++-- 6 files changed, 189 insertions(+), 48 deletions(-) create mode 100644 src/lib/components/refactor/inputfields/SelectInput.svelte create mode 100644 src/lib/components/refactor/inputfields/SliderInput.svelte create mode 100644 src/lib/components/refactor/inputfields/TextInput.svelte create mode 100644 src/lib/components/refactor/inputfields/ToggleInput.svelte diff --git a/src/lib/components/refactor/ComposerForm.svelte b/src/lib/components/refactor/ComposerForm.svelte index d458876..260f480 100644 --- a/src/lib/components/refactor/ComposerForm.svelte +++ b/src/lib/components/refactor/ComposerForm.svelte @@ -3,10 +3,16 @@ import { afterUpdate } from 'svelte'; import { writable } from 'svelte/store'; import { RangeSlider, SlideToggle } from '@skeletonlabs/skeleton'; + import TextInput from './inputfields/TextInput.svelte'; export let me; - const { initialFormData, fields, validators } = $me.context; + const { fields, validators } = $me.context; + + const initialFormData = fields.reduce((acc, field) => { + acc[field.name] = field.placeholder; + return acc; + }, {}); const { form, errors, validate, constraints } = superForm(initialFormData, { validators: validators, @@ -83,31 +89,32 @@ {:else}
- {#each fields as field} + {#each fields as field (field.name)}
- {#if $errors[field]} - {$errors[field]} + {#if $errors[field.name]} + {$errors[field.name]} {:else} -