Use autocompletion input for names
Some checks failed
/ Build App (pull_request) Failing after 21s

This commit is contained in:
Valentin Brandl 2024-07-30 17:34:56 +02:00
parent fc0de8b7e0
commit 4b6f25656b
Signed by: vbrandl
GPG Key ID: CAD4DA1A789125F9

View File

@ -1,9 +1,13 @@
<script lang="ts">
import { enhance } from '$app/forms';
import type { ActionData } from './$types';
import AutoComplete from 'simple-svelte-autocomplete';
export let form: ActionData;
let selectedName: String;
let toCreate = '';
let files: FileList;
let sending = false;
@ -21,6 +25,12 @@
.map(([k, v]) => `${(size / k).toFixed(1)} ${v}B`)[0] ?? `${size} bytes`
);
};
async function loadNames(keyword: String) {
const url = "./names";
const response = await fetch(url);
return await response.json();
}
</script>
<form
@ -44,14 +54,14 @@
<div class="field">
<label for="name" class="label">Name</label>
<div class="control">
<input
id="name"
class="input"
type="text"
name="name"
placeholder="Name"
value={form?.name ?? ''}
required
<AutoComplete
id="name"
name="name"
create={true}
bind:selectedItem={selectedName}
bind:text={selectedName}
createText=""
searchFunction={loadNames}
/>
</div>
{#if form?.field === 'name'}
@ -69,10 +79,10 @@
<span class="file-cta">
<span class="file-label">Fotos auswählen...</span>
</span>
{#if files}
<span class="file-name"
>{files.length} Bild{#if files.length > 1}er{/if} ausgewählt ({fileSize(files)})</span
>
{#if files && files?.length !== 0}
<span class="file-name">
{files.length} Bild{#if files.length > 1}er{/if} ausgewählt ({fileSize(files)})
</span>
{:else}
<span class="file-name">Keine Bilder ausgewählt</span>
{/if}