Birth date and time: our own Hungarian fields
The browser's date and time inputs follow the operating system's or the browser's region, not the page: Safari wanted US order and AM/PM (and did not take minutes without it), Chrome showed its own language. Now the year, a month list with Hungarian names and a day list, and hour and minute fields (24-hour, the cursor moves on after the hour), the same in every browser. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -1104,3 +1104,13 @@ span.tarot-fan-card { cursor: default; }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.tarot-flip-inner, .tarot-fan-card, .tarot-demo-text { transition: none; animation: none; }
|
||||
}
|
||||
|
||||
/* Birth date and time: our own Hungarian fields (not the browser's date and time inputs) */
|
||||
.birth-fields { border: 0; margin: 0; padding: 0; min-width: 0; }
|
||||
.birth-fields legend { padding: 0; margin-bottom: 8px; }
|
||||
.birth-row { display: flex; align-items: center; gap: 8px; }
|
||||
.birth-year { width: 5.5em; flex: none; }
|
||||
.birth-month { flex: 1 1 auto; min-width: 0; }
|
||||
.birth-day { width: 5.2em; flex: none; }
|
||||
.birth-time { width: 4.4em; flex: none; text-align: center; }
|
||||
.birth-colon { color: var(--muted); font-weight: 600; }
|
||||
|
||||
@@ -16,6 +16,41 @@ const ERRORS: Record<string, string> = {
|
||||
invalid_date: "Érvénytelen dátum.",
|
||||
};
|
||||
|
||||
const MONTHS = [
|
||||
"január",
|
||||
"február",
|
||||
"március",
|
||||
"április",
|
||||
"május",
|
||||
"június",
|
||||
"július",
|
||||
"augusztus",
|
||||
"szeptember",
|
||||
"október",
|
||||
"november",
|
||||
"december",
|
||||
];
|
||||
|
||||
const pad = (n: number) => String(n).padStart(2, "0");
|
||||
const daysIn = (year: number, month: number) => new Date(Date.UTC(year || 2000, month, 0)).getUTCDate();
|
||||
|
||||
/** "YYYY-MM-DD" from the three fields, or null while it is not a real date. */
|
||||
function composeDate(year: string, month: string, day: string): string | null {
|
||||
const y = Number(year);
|
||||
const m = Number(month);
|
||||
const d = Number(day);
|
||||
if (!/^\d{4}$/.test(year) || y < 1000 || !m || !d || d > daysIn(y, m)) return null;
|
||||
return `${year}-${pad(m)}-${pad(d)}`;
|
||||
}
|
||||
|
||||
/** "HH:MM" from the two fields, or null while it is not a real time. */
|
||||
function composeTime(hour: string, minute: string): string | null {
|
||||
if (!/^\d{1,2}$/.test(hour) || !/^\d{1,2}$/.test(minute)) return null;
|
||||
const h = Number(hour);
|
||||
const m = Number(minute);
|
||||
return h <= 23 && m <= 59 ? `${pad(h)}:${pad(m)}` : null;
|
||||
}
|
||||
|
||||
/** Someone else's chart: added with a name, or (with `chartId`) corrected. */
|
||||
export type PersonTarget = { chartId?: string; name?: string };
|
||||
|
||||
@@ -32,8 +67,16 @@ export function BirthForm({
|
||||
onSaved: (chartId: string) => void;
|
||||
}) {
|
||||
const [name, setName] = useState(person?.name ?? "");
|
||||
const [date, setDate] = useState(initial?.date ?? "");
|
||||
const [time, setTime] = useState(initial?.time?.slice(0, 5) ?? "");
|
||||
// Our own fields, not the browser's date and time inputs: those follow the
|
||||
// operating system's or the browser's region (US order, AM/PM in Safari).
|
||||
const [year, setYear] = useState(initial?.date?.slice(0, 4) ?? "");
|
||||
const [month, setMonth] = useState(initial?.date ? String(Number(initial.date.slice(5, 7))) : "");
|
||||
const [day, setDay] = useState(initial?.date ? String(Number(initial.date.slice(8, 10))) : "");
|
||||
const [hour, setHour] = useState(initial?.time?.slice(0, 2) ?? "");
|
||||
const [minute, setMinute] = useState(initial?.time?.slice(3, 5) ?? "");
|
||||
const minuteRef = useRef<HTMLInputElement>(null);
|
||||
const date = composeDate(year, month, day) ?? "";
|
||||
const time = composeTime(hour, minute) ?? "";
|
||||
const [timeUnknown, setTimeUnknown] = useState(initial ? !initial.time : false);
|
||||
const [country, setCountry] = useState(initial?.country ?? "HU");
|
||||
const [place, setPlace] = useState<Place | null>(
|
||||
@@ -57,8 +100,11 @@ export function BirthForm({
|
||||
e.preventDefault();
|
||||
setError(null);
|
||||
if (person && !name.trim()) return setError("Add meg a nevét.");
|
||||
if (!date) return setError("Add meg a születési dátumot.");
|
||||
if (!timeUnknown && !time) return setError("Add meg a születési időt, vagy jelöld, hogy nem tudod.");
|
||||
if (!year && !month && !day) return setError("Add meg a születési dátumot.");
|
||||
if (!date) return setError("Ellenőrizd a dátumot: az év négy számjegy, és a nap legyen az adott hónapban.");
|
||||
if (date > today) return setError("A születési dátum nem lehet a jövőben.");
|
||||
if (!timeUnknown && !hour && !minute) return setError("Add meg a születési időt, vagy jelöld, hogy nem tudod.");
|
||||
if (!timeUnknown && !time) return setError("Ellenőrizd az időt: óra 0–23, perc 0–59.");
|
||||
if (!place) return setError("Válaszd ki a születési helyet a listából.");
|
||||
setBusy(true);
|
||||
try {
|
||||
@@ -120,37 +166,106 @@ export function BirthForm({
|
||||
</div>
|
||||
)}
|
||||
<div className="grid-2">
|
||||
<div className="field">
|
||||
<label htmlFor="birth-date">Születési dátum</label>
|
||||
<fieldset className="field birth-fields">
|
||||
<legend className="label">Születési dátum</legend>
|
||||
<div className="birth-row">
|
||||
<label className="sr-only" htmlFor="birth-year">
|
||||
Év
|
||||
</label>
|
||||
<input
|
||||
id="birth-date"
|
||||
type="date"
|
||||
className="inp"
|
||||
min="1000-01-01"
|
||||
max={today}
|
||||
value={date}
|
||||
onChange={(e) => setDate(e.target.value)}
|
||||
required
|
||||
id="birth-year"
|
||||
className="inp birth-year"
|
||||
inputMode="numeric"
|
||||
autoComplete="bday-year"
|
||||
placeholder="év"
|
||||
maxLength={4}
|
||||
value={year}
|
||||
onChange={(e) => setYear(e.target.value.replace(/\D/g, ""))}
|
||||
/>
|
||||
<label className="sr-only" htmlFor="birth-month">
|
||||
Hónap
|
||||
</label>
|
||||
<select
|
||||
id="birth-month"
|
||||
className="inp birth-month"
|
||||
autoComplete="bday-month"
|
||||
value={month}
|
||||
onChange={(e) => setMonth(e.target.value)}
|
||||
>
|
||||
<option value="">hónap</option>
|
||||
{MONTHS.map((m, i) => (
|
||||
<option key={m} value={i + 1}>
|
||||
{m}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<label className="sr-only" htmlFor="birth-day">
|
||||
Nap
|
||||
</label>
|
||||
<select
|
||||
id="birth-day"
|
||||
className="inp birth-day"
|
||||
autoComplete="bday-day"
|
||||
value={day}
|
||||
onChange={(e) => setDay(e.target.value)}
|
||||
>
|
||||
<option value="">nap</option>
|
||||
{Array.from({ length: month ? daysIn(Number(year), Number(month)) : 31 }, (_, i) => (
|
||||
<option key={i + 1} value={i + 1}>
|
||||
{i + 1}.
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label htmlFor="birth-time">Születési idő (helyi idő)</label>
|
||||
</fieldset>
|
||||
<fieldset className="field birth-fields">
|
||||
<legend className="label">Születési idő (helyi idő)</legend>
|
||||
<div className="birth-row">
|
||||
<label className="sr-only" htmlFor="birth-hour">
|
||||
Óra
|
||||
</label>
|
||||
<input
|
||||
id="birth-time"
|
||||
type="time"
|
||||
className="inp"
|
||||
value={timeUnknown ? "" : time}
|
||||
id="birth-hour"
|
||||
className="inp birth-time"
|
||||
inputMode="numeric"
|
||||
placeholder="óra"
|
||||
maxLength={2}
|
||||
value={timeUnknown ? "" : hour}
|
||||
disabled={timeUnknown}
|
||||
onChange={(e) => {
|
||||
setTime(e.target.value);
|
||||
const v = e.target.value.replace(/\D/g, "");
|
||||
setHour(v);
|
||||
setAmbiguous(false);
|
||||
// Two digits (or one that cannot start a valid hour): on to the minutes.
|
||||
if (v.length === 2 || (v.length === 1 && Number(v) > 2)) minuteRef.current?.focus();
|
||||
}}
|
||||
/>
|
||||
<span className="birth-colon" aria-hidden="true">
|
||||
:
|
||||
</span>
|
||||
<label className="sr-only" htmlFor="birth-minute">
|
||||
Perc
|
||||
</label>
|
||||
<input
|
||||
id="birth-minute"
|
||||
ref={minuteRef}
|
||||
className="inp birth-time"
|
||||
inputMode="numeric"
|
||||
placeholder="perc"
|
||||
maxLength={2}
|
||||
value={timeUnknown ? "" : minute}
|
||||
disabled={timeUnknown}
|
||||
onChange={(e) => {
|
||||
setMinute(e.target.value.replace(/\D/g, ""));
|
||||
setAmbiguous(false);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<label className="check">
|
||||
<input type="checkbox" checked={timeUnknown} onChange={(e) => setTimeUnknown(e.target.checked)} />
|
||||
Nem tudom a születési időt
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div className="grid-2">
|
||||
|
||||
Reference in New Issue
Block a user