fix(profile): use dd.mm.yyyy date input for birth date field
Some checks failed
CI / Unit & Component Tests (pull_request) Successful in 2m4s
CI / Backend Unit Tests (pull_request) Successful in 1m57s
CI / E2E Tests (pull_request) Failing after 13m53s
CI / Unit & Component Tests (push) Successful in 2m35s
CI / E2E Tests (push) Has been cancelled
CI / Backend Unit Tests (push) Has been cancelled
Some checks failed
CI / Unit & Component Tests (pull_request) Successful in 2m4s
CI / Backend Unit Tests (pull_request) Successful in 1m57s
CI / E2E Tests (pull_request) Failing after 13m53s
CI / Unit & Component Tests (push) Successful in 2m35s
CI / E2E Tests (push) Has been cancelled
CI / Backend Unit Tests (push) Has been cancelled
Replace the browser-native type="date" picker with a text input using the same german format (dd.mm.yyyy with auto-dot insertion) as the document date fields. A hidden input sends the ISO value to the server. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit was merged in pull request #45.
This commit is contained in:
@@ -1,8 +1,41 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { enhance } from '$app/forms';
|
import { enhance } from '$app/forms';
|
||||||
|
import { untrack } from 'svelte';
|
||||||
import { m } from '$lib/paraglide/messages.js';
|
import { m } from '$lib/paraglide/messages.js';
|
||||||
|
|
||||||
let { data, form } = $props();
|
let { data, form } = $props();
|
||||||
|
|
||||||
|
function isoToGerman(iso: string | undefined): string {
|
||||||
|
if (!iso) return '';
|
||||||
|
const match = iso.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
||||||
|
if (!match) return '';
|
||||||
|
return `${match[3]}.${match[2]}.${match[1]}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function germanToIso(german: string): string {
|
||||||
|
const match = german.match(/^(\d{2})\.(\d{2})\.(\d{4})$/);
|
||||||
|
if (!match) return '';
|
||||||
|
return `${match[3]}-${match[2]}-${match[1]}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
let birthDateDisplay = $state(untrack(() => isoToGerman(data.user?.birthDate)));
|
||||||
|
let birthDateIso = $state(untrack(() => data.user?.birthDate ?? ''));
|
||||||
|
|
||||||
|
function handleBirthDateInput(e: Event) {
|
||||||
|
const input = e.target as HTMLInputElement;
|
||||||
|
const digits = input.value.replace(/\D/g, '').slice(0, 8);
|
||||||
|
let formatted: string;
|
||||||
|
if (digits.length <= 2) {
|
||||||
|
formatted = digits;
|
||||||
|
} else if (digits.length <= 4) {
|
||||||
|
formatted = `${digits.slice(0, 2)}.${digits.slice(2)}`;
|
||||||
|
} else {
|
||||||
|
formatted = `${digits.slice(0, 2)}.${digits.slice(2, 4)}.${digits.slice(4)}`;
|
||||||
|
}
|
||||||
|
input.value = formatted;
|
||||||
|
birthDateDisplay = formatted;
|
||||||
|
birthDateIso = germanToIso(formatted);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="mx-auto max-w-7xl px-4 py-8 sm:px-6 lg:px-8">
|
<div class="mx-auto max-w-7xl px-4 py-8 sm:px-6 lg:px-8">
|
||||||
@@ -80,11 +113,13 @@ let { data, form } = $props();
|
|||||||
{m.profile_label_birth_date()}
|
{m.profile_label_birth_date()}
|
||||||
</span>
|
</span>
|
||||||
<input
|
<input
|
||||||
type="date"
|
type="text"
|
||||||
name="birthDate"
|
placeholder="TT.MM.JJJJ"
|
||||||
value={data.user?.birthDate ?? ''}
|
value={birthDateDisplay}
|
||||||
|
oninput={handleBirthDateInput}
|
||||||
class="w-full rounded-sm border border-brand-sand px-3 py-2 font-serif text-sm focus:border-brand-navy focus:outline-none"
|
class="w-full rounded-sm border border-brand-sand px-3 py-2 font-serif text-sm focus:border-brand-navy focus:outline-none"
|
||||||
/>
|
/>
|
||||||
|
<input type="hidden" name="birthDate" value={birthDateIso} />
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label class="block">
|
<label class="block">
|
||||||
|
|||||||
Reference in New Issue
Block a user