From 30fd3a84a1cd24890e361ce2bcd81307382348b2 Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Wed, 22 Jul 2026 00:03:48 +0200 Subject: [PATCH] Accept comma as decimal separator in numeric inputs iOS decimal keyboards in many locales only offer a comma; type=number inputs report an empty value for it, snapping the field to 0. Numeric fields (weight, speed, etc.) are now text inputs with inputMode=decimal backed by a shared NumField component that normalizes ',' to '.' and keeps partial input like "33," alive while typing. Fixes #13 --- CHANGELOG.md | 6 ++++++ frontend/package.json | 2 +- frontend/src/components/NumField.jsx | 31 ++++++++++++++++++++++++++++ frontend/src/components/Stepper.jsx | 10 +++------ frontend/src/views/Workout.jsx | 4 ++-- 5 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 frontend/src/components/NumField.jsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 537629f..23bc34f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v1.2.1 — 2026-07-22 + +- ⌨️ Weight and other numeric fields now accept a comma as decimal separator ("33,5") — iOS + decimal keyboards in many locales only offer a comma, which previously reset the field to 0. + Partial input like "33," no longer snaps to 0 while typing. (#13) + ## v1.2.0 — 2026-07-21 Localization — the whole app now speaks your language. (#7) diff --git a/frontend/package.json b/frontend/package.json index 9af1908..1be143d 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "opengym-frontend", "private": true, - "version": "1.1.1", + "version": "1.2.1", "type": "module", "scripts": { "dev": "vite", diff --git a/frontend/src/components/NumField.jsx b/frontend/src/components/NumField.jsx new file mode 100644 index 0000000..6bdd63d --- /dev/null +++ b/frontend/src/components/NumField.jsx @@ -0,0 +1,31 @@ +import { useRef, useState } from 'react' + +// Numeric input that accepts "," as decimal separator — iOS decimal keypads in many +// locales only offer a comma, and type="number" reports "" for it (value snaps to 0). +// Keeps a local string draft while focused so partial input like "33," survives typing. +export default function NumField({ value, onChange, decimal = true, ...rest }) { + const [draft, setDraft] = useState(null) + const committed = useRef(null) + // external change (e.g. −/+ buttons) while a draft is showing → drop the draft + if (draft !== null && committed.current !== value) { setDraft(null); committed.current = null } + const commit = raw => { + let s = raw.replace(/,/g, '.').replace(/[^0-9.]/g, '') + const i = s.indexOf('.') + if (i !== -1) s = decimal ? s.slice(0, i + 1) + s.slice(i + 1).replace(/\./g, '') : s.slice(0, i) + const n = s === '' || s === '.' ? 0 : Math.max(0, parseFloat(s)) + committed.current = n + setDraft(s) + onChange(n) + } + return ( + e.target.select()} + onChange={e => commit(e.target.value)} + onBlur={() => { setDraft(null); committed.current = null }} + {...rest} + /> + ) +} diff --git a/frontend/src/components/Stepper.jsx b/frontend/src/components/Stepper.jsx index 9db809a..2801f82 100644 --- a/frontend/src/components/Stepper.jsx +++ b/frontend/src/components/Stepper.jsx @@ -1,16 +1,12 @@ +import NumField from './NumField.jsx' + // Number field with −/+ buttons; tapping the field selects its content so typing replaces. export default function Stepper({ value, step = 1, onChange, decimal = true, className = '', label }) { const set = v => onChange(Math.max(0, Math.round((v || 0) * 100) / 100)) const inner = (
- e.target.select()} - onChange={e => onChange(e.target.value === '' ? 0 : Math.max(0, parseFloat(e.target.value) || 0))} - /> +
) diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx index 2e3da0d..de2b422 100644 --- a/frontend/src/views/Workout.jsx +++ b/frontend/src/views/Workout.jsx @@ -8,6 +8,7 @@ import { fmtNum, fmtDate, todayISO, DAYN } from '../lib/format.js' import { beep, vibrate } from '../lib/sound.js' import { t } from '../lib/i18n.js' import Media from '../components/Media.jsx' +import NumField from '../components/NumField.jsx' import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet, confirmSheet } from '../sheets.jsx' /* ---------- start chooser (no active workout) ---------- */ @@ -63,8 +64,7 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onBumpAll, onAddS const cell = (s, i, col, cls) => (
- e.target.select()} - onChange={e => onField(i, col.f, e.target.value === '' ? 0 : Math.max(0, (col.dec ? parseFloat(e.target.value) : Math.round(parseFloat(e.target.value))) || 0))} /> + onField(i, col.f, v)} />
)