From 8e0550bc7186ab55263de9480aef54b6471cbe09 Mon Sep 17 00:00:00 2001 From: Daniel Jovanovic Date: Wed, 3 Aug 2022 10:29:56 +0200 Subject: [PATCH] Correctly handle unset/invalid date values --- src/ClientApp/src/components/BohrungForm.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ClientApp/src/components/BohrungForm.js b/src/ClientApp/src/components/BohrungForm.js index 25647b4..6ef768f 100644 --- a/src/ClientApp/src/components/BohrungForm.js +++ b/src/ClientApp/src/components/BohrungForm.js @@ -109,9 +109,12 @@ export default function BohrungForm(props) { const currentInteraction = currentBohrung?.id ? "edit" : currentBohrung?.bezeichnung ? "copy" : "add"; const onSubmit = (formData) => { - const date = new Date(formData.datum); // save date as UTC date ignoring the current timezone - formData.datum = new Date(date - date.getTimezoneOffset() * 60000).toISOString(); + const date = new Date(formData.datum); + if (!isNaN(date)) { + formData.datum = new Date(date - date.getTimezoneOffset() * 60000).toISOString(); + } + formData.geometrie = { coordinates: [Number(formData.x_coordinate), Number(formData.y_coordinate)], type: "Point" }; currentBohrung.id ? editBohrung(formData).finally(() => reset(formData))