make reported user nullable
All checks were successful
delpoy / build-and-deploy (push) Successful in 44s

This commit is contained in:
2023-11-03 18:10:02 +01:00
parent 72eeb59230
commit 81d97380ca
11 changed files with 107 additions and 65 deletions

View File

@@ -1,7 +1,11 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte';
export let id: string | null = null;
export let value = '';
export let inputValue = '';
export let suggestionRequired = false;
export let emptyAllowed = false;
export let searchSuggestionFunc: (
input: string
) => Promise<{ name: string; value: string }[]> = () => Promise.resolve([]);
@@ -10,7 +14,8 @@
export let label: string | null = null;
export let required = false;
let inputValue: string;
const dispatch = createEventDispatcher();
let searchSuggestions: { name: string; value: string }[] = [];
$: if (!suggestionRequired) value = inputValue;
</script>
@@ -47,13 +52,18 @@
value = searchSuggestion.value;
searchSuggestions = [];
e.target?.setCustomValidity('');
dispatch('submit', { input: inputValue, value: value });
} else if (inputValue === '' && emptyAllowed) {
dispatch('submit', { input: '', value: '' });
}
});
}}
on:invalid={(e) => {
if (invalidMessage != null) e.target?.setCustomValidity(invalidMessage);
}}
pattern={suggestionRequired ? `${value ? inputValue : 'a^'}` : null}
pattern={suggestionRequired
? `${value ? inputValue : 'a^' + (emptyAllowed ? '|$^' : '')}`
: null}
/>
</div>
@@ -68,6 +78,7 @@
inputValue = searchSuggestion.name;
value = searchSuggestion.value;
searchSuggestions = [];
dispatch('submit', { input: inputValue, value: value });
}}>{searchSuggestion.name}</button
>
</li>
@@ -76,6 +87,7 @@
{/if}
</div>
<!-- close the search suggestions box when clicking outside -->
{#if inputValue && searchSuggestions.length !== 0}
<button
class="absolute top-0 left-0 z-10 w-full h-full cursor-default"