Fix client-side error when editing date with keyboard (Closes #43)

This commit is contained in:
Sebastien Castiel
2024-01-14 12:47:52 -05:00
parent beae336666
commit 43f7ca700b

View File

@@ -165,9 +165,7 @@ export function ExpenseForm({
<Input
className="date-base"
type="date"
value={(field.value ?? new Date())
.toISOString()
.substring(0, 10)}
defaultValue={formatDate(field.value)}
onChange={(event) => {
return field.onChange(new Date(event.target.value))
}}
@@ -552,3 +550,8 @@ export function ExpenseForm({
</Form>
)
}
function formatDate(date?: Date) {
if (!date || isNaN(date as any)) date = new Date()
return date.toISOString().substring(0, 10)
}