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