fix(budget): seed edit fields with two decimals and allow signed amounts for refunds (#2175, #2176)

This commit is contained in:
Maurice
2026-09-01 15:07:26 +02:00
committed by Maurice
parent 49b0ce28d5
commit d1aa573167
18 changed files with 717 additions and 78 deletions
@@ -1,6 +1,6 @@
import { useRef, type InputHTMLAttributes, type Ref } from 'react'
export type NumericMode = 'integer' | 'decimal' | 'signed'
export type NumericMode = 'integer' | 'decimal' | 'signed' | 'signed-decimal'
const SANITIZERS: Record<NumericMode, (raw: string) => string> = {
// Digits only — quantities, weights, day counts.
@@ -14,6 +14,14 @@ const SANITIZERS: Record<NumericMode, (raw: string) => string> = {
const digits = raw.replace(/[^0-9.]/g, '')
return negative ? `-${digits}` : digits
},
// 'decimal' plus a leading '-' — money fields that accept a refund (#2176).
// Distinct from 'signed' on purpose: that one strips the comma, which a
// European keypad needs for amounts.
'signed-decimal': raw => {
const negative = raw.trimStart().startsWith('-')
const digits = raw.replace(/[^0-9.,]/g, '')
return negative ? `-${digits}` : digits
},
}
type Props = Omit<InputHTMLAttributes<HTMLInputElement>, 'type' | 'onChange' | 'value'> & {