diff options
| author | Sebastien Castiel <sebastien@castiel.me> | 2024-01-14 12:47:52 -0500 |
|---|---|---|
| committer | Sebastien Castiel <sebastien@castiel.me> | 2024-01-14 12:47:52 -0500 |
| commit | 43f7ca700b3fe44819b37a435ece97ab92df683d (patch) | |
| tree | a262cd46894e14b0fc74043ac3ee0cc72cfd75da /src/components/expense-form.tsx | |
| parent | beae3366667b54b83e20f7e8d532f694c81bc5d0 (diff) | |
Fix client-side error when editing date with keyboard (Closes #43)
Diffstat (limited to 'src/components/expense-form.tsx')
| -rw-r--r-- | src/components/expense-form.tsx | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/components/expense-form.tsx b/src/components/expense-form.tsx index c1652ca..cfc749a 100644 --- a/src/components/expense-form.tsx +++ b/src/components/expense-form.tsx @@ -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) +} |
