Skip to content

Typing a minus in a Pool's capacity no longer makes it unlimited - #658

Merged
MerciHanrim merged 1 commit into
mainfrom
half-typed-number-not-blank
Nov 24, 2026
Merged

MerciHanrim merged 1 commit into
mainfrom
half-typed-number-not-blank

Conversation

@MerciHanrim

Copy link
Copy Markdown
Owner

Part of #615 (item 2 only; the trigger delay of item 1 is the next PR, see below).

What was wrong

Four Inspector number fields allow a blank and store what is typed as it is typed: a Pool's Capacity (blank = unlimited) and a Parameter's Min, Max and Step. A number input reports a half-typed - or 1e as the empty value, the same as a blank, and DraftNumberInput committed null for it.

Measured on main b17aa721 (each field from a set value, one key at a time):

  • -: the value is cleared at once, the autosave writes it, and the run resets. Leaving the field keeps it cleared. For a capacity, cleared means unlimited, and -5 ends unlimited, because 5 makes -5, which is refused.
  • 1e: the 1 stores 1, then the e clears it. It stays cleared.
  • A real blank clears too, as intended.
  • In the two fields that do not allow a blank (Pool starting amount, Parameter value), - and a blank stored nothing.

The rule, and the check made before the change

validity.badInput is true while a number input's text cannot be read as a number, and false for a real blank.

Measured in the app's four fields before any change (Chromium 151, the only engine my automated runs use):

  • -: badInput true;
  • 1e: badInput true;
  • 1e5: badInput false, value 1e5;
  • a real blank: badInput false.

The change (src/components/DraftNumberInput.tsx)

An empty value with badInput is an edit in progress:

  • it commits nothing and the field is aria-invalid;
  • the field's hint shows, where it has one (the capacity's "Enter a number that is 0 or greater.");
  • leaving the field drops the draft and shows the stored value, as the fields that do not allow a blank already did.

A real blank still commits null where a blank is allowed. A valid number on the way, such as the 1 of 1e, is still committed as typed, as in every such field.

Tests (e2e/number-field-blank.spec.ts), written first

There is one test per field: capacity, Min, Max, Step.

  • For -: the stored value and the autosave are unchanged, the run's step is kept, the field is aria-invalid (and for the capacity its hint shows), and on leaving the field shows the stored value again.
  • For 1e: the value is the 1 stored by its 1 key, not cleared.
  • A real blank still clears, with the run reset.

A controls test covers the Pool starting amount and the Parameter value, for - and a blank, with nothing stored as before.

On main's code the four field tests fail on - (their 1e part is not reached) and the controls test passes. With the change all pass.

Two of my test mistakes were corrected before the change; the earlier runs are kept:

  • The 1e expectation first said "unchanged", but its 1 is a valid number and is stored.
  • The controls test compared against a fixed step, which a repeated start value does not reset.

Checks

  • npx tsc -b: clean.

  • npm run lint: 88 warnings, the baseline.

  • All check:* scripts: pass.

  • Unit suite: 5758 passed, 4 skipped.

  • Related e2e, one worker, no retries:

    • e2e/number-field-blank.spec.ts: 7 passed;
    • e2e/field-undo.spec.ts, e2e/model-panels.spec.ts and e2e/parameter-activator-authoring.spec.ts: 33 passed.

    None holds a screenshot comparison.

Not in this PR

  • Min, Max and Step have no visible hint for any invalid input, 1e400 included. They have only aria-invalid, before and after this change. A hint there needs a new catalog key in every language.

  • The trigger delay (item 1, next PR): its field (Inspector.tsx:886-895) is a plain <input type="number"> that stores Number(v) on every keystroke, with no draft. It can reuse this rule:

    • DraftNumberInput with allowEmpty (a blank removes the delay);
    • valid={(n) => Number.isInteger(n) && n >= 0};
    • then a half-typed -, a -2 and a 1.5 would store nothing.

    Its engine behaviour for an invalid delay (treated as 0 with a diagnostic) is known from the code (step.ts:1064-1074), not measured.

  • Items 5 and 3 of Number fields, drafts and import dialogs: five findings from the 2026-11-15 review #615.

What it touches

DraftNumberInput tells a half-typed number (-, 1e), which a number input also reports as an empty value, from a real blank by validity.badInput: it commits nothing and is marked invalid; a real blank still commits null where a blank is allowed. Part of #615.
@MerciHanrim MerciHanrim added the bug Something isn't working label Nov 24, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying cozy-loop-studio with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4520b23
Status: ✅  Deploy successful!
Preview URL: https://f9041d84.cozy-loop-studio.pages.dev
Branch Preview URL: https://half-typed-number-not-blank.cozy-loop-studio.pages.dev

View logs

@MerciHanrim
MerciHanrim merged commit caa763c into main Nov 24, 2026
13 checks passed
@MerciHanrim
MerciHanrim deleted the half-typed-number-not-blank branch November 24, 2026 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant