Skip to content

fix(web): accept comma or period decimal separator when saving locations#536

Open
mrosseel wants to merge 1 commit into
brickbots:mainfrom
mrosseel:fix/location-decimal-separator
Open

fix(web): accept comma or period decimal separator when saving locations#536
mrosseel wants to merge 1 commit into
brickbots:mainfrom
mrosseel:fix/location-decimal-separator

Conversation

@mrosseel

Copy link
Copy Markdown
Collaborator

Problem

Saving a location in the web UI silently fails in a comma-decimal browser locale (much of Europe). Typing 51,3 or 51.3 and clicking Save Location does nothing — the button looks active but no request is sent. Only integer values (e.g. 51) save.

Root cause

The coordinate/altitude/error inputs on both the add and edit forms are <input type="number">. For a number input the browser returns an empty .value when the entered text doesn't match its locale's number format (a dot in a comma locale, or vice-versa). The client-side validation (checkFields()) then treats the field as empty, returns invalid, and the submit handler calls e.preventDefault(). The request never reaches the server. Integers have no separator, so they always parse — hence "integers work, decimals don't."

Same class of bug as #291 (equipment focal-length decimal crash).

Fix

  • Inputs → type="text" inputmode="decimal" on the coordinate/altitude/error/DMS fields (keeps the mobile numeric keypad, but the browser no longer blanks locale-mismatched values).
  • JS normalises both separators to a period before validation (validateField, DMSToDecimal) and rewrites values to period-form on submit, so the server always receives valid floats.
  • Server-side parse_coordinate() tolerates a comma and turns a missing/garbage field into a friendly validation message instead of an uncaught 500.

Tests

Adds tests/test_server_coordinates.py (unit) covering comma/period/integer/whitespace parsing and the missing/garbage error paths.

Note: the existing Selenium test_web_locations.py never caught this because it types dotted decimals into a default en-US Chrome (where dots are valid), and the tests/website/ suite isn't run in CI (it needs an external Selenium Grid and self-skips). The new server-side unit test runs under pytest -m unit.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VaxurSrCzxrsfJrSjfA5bo

Coordinate/altitude fields on the web location add & edit forms were
<input type="number">. In a comma-decimal browser locale the browser
returns an empty .value for a period-formatted number (and vice-versa),
so the client-side validation saw the field as empty and silently
blocked submit — the Save button appeared active but did nothing.
Integer entries (no separator) worked, decimals did not.

Switch the numeric inputs to type=text inputmode=decimal, normalise
both separators to a period in JS before validation and submit, and
add a tolerant parse_coordinate() on the server so a stray comma yields
a friendly validation message instead of a 500.

Same bug class as brickbots#291 (equipment focal-length decimal crash).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant