Some checks failed
CI / Unit & Component Tests (push) Has been cancelled
CI / Backend Unit Tests (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
CI / Unit & Component Tests (pull_request) Failing after 1m46s
CI / Backend Unit Tests (pull_request) Failing after 2m37s
CI / E2E Tests (pull_request) Failing after 1h48m16s
Clearing the input set value='' but did not call onchange, so the korrespondenz filter strip never re-fetched. Added onchange?.() in the empty-display branch and added a test that confirms the callback fires. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
77 lines
1.4 KiB
Svelte
77 lines
1.4 KiB
Svelte
<script lang="ts">
|
|
import { isoToGerman, handleGermanDateInput, germanToIso } from '$lib/utils/date';
|
|
import { m } from '$lib/paraglide/messages.js';
|
|
|
|
interface Props {
|
|
value?: string;
|
|
errorMessage?: string | null;
|
|
name?: string;
|
|
id?: string;
|
|
placeholder?: string;
|
|
class?: string;
|
|
onchange?: () => void;
|
|
}
|
|
|
|
let {
|
|
value = $bindable(''),
|
|
errorMessage = $bindable<string | null>(null),
|
|
name,
|
|
id,
|
|
placeholder,
|
|
class: className = '',
|
|
onchange
|
|
}: Props = $props();
|
|
|
|
let display = $state(isoToGerman(value ?? ''));
|
|
|
|
function handleInput(e: Event) {
|
|
const result = handleGermanDateInput(e);
|
|
display = result.display;
|
|
|
|
if (result.display === '') {
|
|
value = '';
|
|
errorMessage = null;
|
|
onchange?.();
|
|
return;
|
|
}
|
|
|
|
if (result.display.length < 10) {
|
|
value = '';
|
|
errorMessage = m.form_date_error();
|
|
return;
|
|
}
|
|
|
|
const iso = germanToIso(result.display);
|
|
if (!iso) {
|
|
value = '';
|
|
errorMessage = m.form_date_error();
|
|
return;
|
|
}
|
|
|
|
const [, mo, d] = iso.split('-').map(Number);
|
|
if (mo < 1 || mo > 12 || d < 1 || d > 31) {
|
|
value = '';
|
|
errorMessage = m.form_date_error();
|
|
return;
|
|
}
|
|
|
|
value = iso;
|
|
errorMessage = null;
|
|
onchange?.();
|
|
}
|
|
</script>
|
|
|
|
<input
|
|
type="text"
|
|
inputmode="numeric"
|
|
maxlength="10"
|
|
id={id}
|
|
value={display}
|
|
placeholder={placeholder ?? m.form_placeholder_date()}
|
|
oninput={handleInput}
|
|
class={className}
|
|
/>
|
|
{#if name}
|
|
<input type="hidden" name={name} value={value} />
|
|
{/if}
|