Skip to content

Conversation

@mmalerba
Copy link
Contributor

@mmalerba mmalerba commented Feb 5, 2026

Supports binding null to a <input type=number>.

  • Treats a model value of null the same as a model value of NaN
  • When the user clears the input, reports null rather than NaN
  • When the user types an invalid number, model does not update, raises
    an error via the parse errors mechanism

@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: forms labels Feb 5, 2026
@ngbot ngbot bot added this to the Backlog milestone Feb 5, 2026
@mmalerba mmalerba changed the title fix(forms): simplify design of parse errors feat(forms): support binding null to number input Feb 5, 2026
@mmalerba mmalerba force-pushed the sf/number branch 4 times, most recently from 66e5dea to 714ff23 Compare February 9, 2026 22:21
@mmalerba mmalerba requested review from alxhub and leonsenft February 9, 2026 22:22
@mmalerba mmalerba marked this pull request as ready for review February 9, 2026 22:22
@mmalerba mmalerba requested a review from kirjs February 9, 2026 22:22
): () => void {
let updateMode = false;
const input = parent.nativeFormElement;
// TODO: (perf) ok to always create this?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the alternative? Could we only create this if we know it's a numeric input?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we could look at the input type and only do it for types that have parsing. (e.g. type=text wouldn't need it), wanted to see if people thought that's worth it or not

Copy link
Contributor

@leonsenft leonsenft Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a compelling reason not to?

I guess it means this call site needs to encode some of the same work done inside getNativeControlValue() to know whether it should handle parse errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it felt like duplicating logic that checks the input type, that we already have elsewhere. then if we ever needed to add parsing to another type we'd have to remember to opt it in here in addition to adding the logic for it

Changes `parsedErrors` to a `linkedSignal` based on the model value.
This ensures that the parse errors are reset if the model changes from
outside the control.
Integrates native inputs with the new parseErrors API so that they can
report parse errors when the user types an un-parsable value (e.g. "42e"
in a number field).

When a user types an un-parsable value, the model does not update. It
retains its previous value and a parse error is added for the control
that received the un-parsable value.
Supports binding `null` to a `<input type=number>`.

- Binding in `null` clears the input
- Binding in `NaN` also clears the input
- When the user clears the input, the model is set to `null`
- The model is _never_ set to `NaN` based on user interaction. It is
  either set to `null` if the user cleared the input, or is unchanged
  and a parse error added if the user entered an invalid number like
  "42e"
native controls and custom controls (via transformedValue) use similar
parsing logic but it needs to be hooked up differently. This commit
extracts the common bits into a shared piece.
Copy link
Contributor

@leonsenft leonsenft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed-for: public-api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants