bug fix for atemschutz
This commit is contained in:
@@ -268,36 +268,6 @@ function Atemschutz() {
|
||||
return `${year}-${m[2]}-${m[3]}`;
|
||||
};
|
||||
|
||||
// Ref to the dialog content — used to read date inputs directly from DOM on submit
|
||||
const dialogContentRef = React.useRef<HTMLDivElement>(null);
|
||||
|
||||
/** Read all date inputs from DOM at submit time — bulletproof Safari workaround */
|
||||
const readDatesFromDOM = (): Record<string, string | undefined> => {
|
||||
const result: Record<string, string | undefined> = {};
|
||||
const dateFieldNames = [
|
||||
'lehrgang_datum',
|
||||
'untersuchung_datum',
|
||||
'untersuchung_gueltig_bis',
|
||||
'leistungstest_datum',
|
||||
'leistungstest_gueltig_bis',
|
||||
];
|
||||
if (!dialogContentRef.current) {
|
||||
// Fallback: read from React state
|
||||
for (const name of dateFieldNames) {
|
||||
result[name] = normalizeDate((form as any)[name] || undefined);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
for (const name of dateFieldNames) {
|
||||
const input = dialogContentRef.current.querySelector(`input[name="${name}"]`) as HTMLInputElement | null;
|
||||
const domVal = input?.value || '';
|
||||
const stateVal = (form as any)[name] || '';
|
||||
// Use DOM value if available, otherwise fall back to React state
|
||||
result[name] = normalizeDate(domVal || stateVal || undefined);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
setDialogError(null);
|
||||
|
||||
@@ -308,29 +278,15 @@ function Atemschutz() {
|
||||
|
||||
setDialogLoading(true);
|
||||
try {
|
||||
// Read date values directly from DOM (Safari workaround)
|
||||
const dates = readDatesFromDOM();
|
||||
|
||||
// DEBUG: remove after confirming it works
|
||||
const debugInfo: Record<string, string> = {};
|
||||
const ref = dialogContentRef.current;
|
||||
if (ref) {
|
||||
for (const n of ['lehrgang_datum', 'leistungstest_gueltig_bis']) {
|
||||
const el = ref.querySelector(`input[name="${n}"]`) as HTMLInputElement | null;
|
||||
debugInfo[n] = el ? `found, value="${el.value}"` : 'NOT FOUND in DOM';
|
||||
}
|
||||
}
|
||||
alert('DOM dates:\n' + JSON.stringify(dates, null, 2) + '\n\nDebug:\n' + JSON.stringify(debugInfo, null, 2));
|
||||
|
||||
if (editingId) {
|
||||
const payload: UpdateAtemschutzPayload = {
|
||||
atemschutz_lehrgang: form.atemschutz_lehrgang,
|
||||
lehrgang_datum: dates.lehrgang_datum,
|
||||
untersuchung_datum: dates.untersuchung_datum,
|
||||
untersuchung_gueltig_bis: dates.untersuchung_gueltig_bis,
|
||||
lehrgang_datum: normalizeDate(form.lehrgang_datum || undefined),
|
||||
untersuchung_datum: normalizeDate(form.untersuchung_datum || undefined),
|
||||
untersuchung_gueltig_bis: normalizeDate(form.untersuchung_gueltig_bis || undefined),
|
||||
untersuchung_ergebnis: (form.untersuchung_ergebnis as UntersuchungErgebnis) || undefined,
|
||||
leistungstest_datum: dates.leistungstest_datum,
|
||||
leistungstest_gueltig_bis: dates.leistungstest_gueltig_bis,
|
||||
leistungstest_datum: normalizeDate(form.leistungstest_datum || undefined),
|
||||
leistungstest_gueltig_bis: normalizeDate(form.leistungstest_gueltig_bis || undefined),
|
||||
leistungstest_bestanden: form.leistungstest_bestanden,
|
||||
bemerkung: form.bemerkung || undefined,
|
||||
};
|
||||
@@ -340,12 +296,12 @@ function Atemschutz() {
|
||||
const payload: CreateAtemschutzPayload = {
|
||||
user_id: form.user_id,
|
||||
atemschutz_lehrgang: form.atemschutz_lehrgang,
|
||||
lehrgang_datum: dates.lehrgang_datum,
|
||||
untersuchung_datum: dates.untersuchung_datum,
|
||||
untersuchung_gueltig_bis: dates.untersuchung_gueltig_bis,
|
||||
lehrgang_datum: normalizeDate(form.lehrgang_datum || undefined),
|
||||
untersuchung_datum: normalizeDate(form.untersuchung_datum || undefined),
|
||||
untersuchung_gueltig_bis: normalizeDate(form.untersuchung_gueltig_bis || undefined),
|
||||
untersuchung_ergebnis: (form.untersuchung_ergebnis as UntersuchungErgebnis) || undefined,
|
||||
leistungstest_datum: dates.leistungstest_datum,
|
||||
leistungstest_gueltig_bis: dates.leistungstest_gueltig_bis,
|
||||
leistungstest_datum: normalizeDate(form.leistungstest_datum || undefined),
|
||||
leistungstest_gueltig_bis: normalizeDate(form.leistungstest_gueltig_bis || undefined),
|
||||
leistungstest_bestanden: form.leistungstest_bestanden,
|
||||
bemerkung: form.bemerkung || undefined,
|
||||
};
|
||||
@@ -626,7 +582,7 @@ function Atemschutz() {
|
||||
<DialogTitle>
|
||||
{editingId ? 'Atemschutzträger bearbeiten' : 'Neuen Atemschutzträger anlegen'}
|
||||
</DialogTitle>
|
||||
<DialogContent ref={dialogContentRef}>
|
||||
<DialogContent>
|
||||
{dialogError && (
|
||||
<Alert severity="error" sx={{ mb: 2, mt: 1 }}>
|
||||
{dialogError}
|
||||
@@ -685,11 +641,12 @@ function Atemschutz() {
|
||||
<Grid item xs={6}>
|
||||
<TextField
|
||||
label="Lehrgang Datum"
|
||||
type="date"
|
||||
size="small"
|
||||
fullWidth
|
||||
defaultValue={form.lehrgang_datum}
|
||||
inputProps={{ name: 'lehrgang_datum' }}
|
||||
placeholder="JJJJ-MM-TT"
|
||||
value={form.lehrgang_datum}
|
||||
onChange={(e) => handleFormChange('lehrgang_datum', e.target.value)}
|
||||
helperText="Format: 2025-03-01"
|
||||
InputLabelProps={{ shrink: true }}
|
||||
/>
|
||||
</Grid>
|
||||
@@ -703,22 +660,24 @@ function Atemschutz() {
|
||||
<Grid item xs={6}>
|
||||
<TextField
|
||||
label="Untersuchung Datum"
|
||||
type="date"
|
||||
size="small"
|
||||
fullWidth
|
||||
defaultValue={form.untersuchung_datum}
|
||||
inputProps={{ name: 'untersuchung_datum' }}
|
||||
placeholder="JJJJ-MM-TT"
|
||||
value={form.untersuchung_datum}
|
||||
onChange={(e) => handleFormChange('untersuchung_datum', e.target.value)}
|
||||
helperText="Format: 2023-02-08"
|
||||
InputLabelProps={{ shrink: true }}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<TextField
|
||||
label="Gültig bis"
|
||||
type="date"
|
||||
size="small"
|
||||
fullWidth
|
||||
defaultValue={form.untersuchung_gueltig_bis}
|
||||
inputProps={{ name: 'untersuchung_gueltig_bis' }}
|
||||
placeholder="JJJJ-MM-TT"
|
||||
value={form.untersuchung_gueltig_bis}
|
||||
onChange={(e) => handleFormChange('untersuchung_gueltig_bis', e.target.value)}
|
||||
helperText="Format: 2028-02-08"
|
||||
InputLabelProps={{ shrink: true }}
|
||||
/>
|
||||
</Grid>
|
||||
@@ -751,22 +710,24 @@ function Atemschutz() {
|
||||
<Grid item xs={6}>
|
||||
<TextField
|
||||
label="Leistungstest Datum"
|
||||
type="date"
|
||||
size="small"
|
||||
fullWidth
|
||||
defaultValue={form.leistungstest_datum}
|
||||
inputProps={{ name: 'leistungstest_datum' }}
|
||||
placeholder="JJJJ-MM-TT"
|
||||
value={form.leistungstest_datum}
|
||||
onChange={(e) => handleFormChange('leistungstest_datum', e.target.value)}
|
||||
helperText="Format: 2025-08-25"
|
||||
InputLabelProps={{ shrink: true }}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<TextField
|
||||
label="Gültig bis"
|
||||
type="date"
|
||||
size="small"
|
||||
fullWidth
|
||||
defaultValue={form.leistungstest_gueltig_bis}
|
||||
inputProps={{ name: 'leistungstest_gueltig_bis' }}
|
||||
placeholder="JJJJ-MM-TT"
|
||||
value={form.leistungstest_gueltig_bis}
|
||||
onChange={(e) => handleFormChange('leistungstest_gueltig_bis', e.target.value)}
|
||||
helperText="Format: 2026-08-25"
|
||||
InputLabelProps={{ shrink: true }}
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
Reference in New Issue
Block a user