Repository navigation
Clearing an optional Number input stores 0 instead of a missing value #9988
Description
Describe the bug
Clearing an optional Number input changes the value to 0 instead of restoring an empty value. The serialized annotation then contains a numeric result with value.number: 0.
This matters for measurement workflows: an unavailable or withdrawn measurement must remain missing, while an explicitly entered zero must remain a valid number when the configuration permits it. The same distinction is needed for optional per-region measurements without removing the region itself. Downstream tracking: AI4S-YB/pineapplehub#22.
To Reproduce
- Use this configuration, with no default value and no required constraint:
<View>
<Text name="text" value="$text"/>
<Number name="measurement" toName="text"/>
</View>- Import
[{"text":"Sample"}]and open the task. - Observe that the Number input starts empty.
- Type
12, select its contents and delete them. - Inspect the input and the serialized annotation.
Actual result: the input displays 0, and a Number result with {"number":0} is serialized.
Expected behavior
The input returns to blank, and the optional measurement result is omitted, matching its initial missing state. Entering 0 explicitly must still preserve a zero result. For per-region controls, clearing a measurement must preserve the region and unrelated results.
Environment and evidence
- Reproduced with the original Label Studio 1.23.2 frontend in Chromium 152 on Linux.
- Source inspection at current
developcommitc013134ad91f1cdbba3b7ac5ca3a5eacaf942884finds the same input conversion. This is a source finding; the full develop application has not yet been run for this report. - The optional, no-default configuration above rules out required/default handling as the cause. The behavior also occurs without a positive minimum.
Root cause and proposed scope
Number.onChange uses +e.target.value. JavaScript converts the empty string to 0. The existing model already permits null and its existing result-update/serialization path supports absence.
An isolated 1.23.2 frontend prototype passing null for an empty string preserves blank values through serialization and reload, including per-region values while retaining region masks and other measurements. It does not establish a production backend round trip or completion of the upstream test suite.
The proposed fix is limited to empty-input normalization, with regression tests in the existing unit and integration suites. It should preserve explicit zero, negative values, validation, defaults, sliders and per-region/per-item binding; no new result format is needed.
Related work
I searched Number/empty/clear/null reports and PRs in this repository and the archived frontend repository on 2026-10-19 without finding a direct match.
- label-studio-frontend#573 established an initially empty Number when no default is set.
- label-studio-frontend#575 addressed required per-region defaults.
- #5221 addressed Number validation.
- #8882 addressed negative values.
Those changes are related compatibility context, not duplicate reports of clearing an optional input.
Implementation: #9989, with the focused source fix and unit/integration regression tests. Runtime CI and source-built 1.23.2 validation remain pending.
Activity