fix(web): accept comma or period decimal separator when saving locations#536
Open
mrosseel wants to merge 1 commit into
Open
fix(web): accept comma or period decimal separator when saving locations#536mrosseel wants to merge 1 commit into
mrosseel wants to merge 1 commit into
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Saving a location in the web UI silently fails in a comma-decimal browser locale (much of Europe). Typing
51,3or51.3and 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.valuewhen 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 callse.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
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).validateField,DMSToDecimal) and rewrites values to period-form on submit, so the server always receives valid floats.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.pynever caught this because it types dotted decimals into a default en-US Chrome (where dots are valid), and thetests/website/suite isn't run in CI (it needs an external Selenium Grid and self-skips). The new server-side unit test runs underpytest -m unit.🤖 Generated with Claude Code
https://claude.ai/code/session_01VaxurSrCzxrsfJrSjfA5bo