Skip to content

feat(forms): support binding null to number input#66917

Closed
mmalerba wants to merge 7 commits intoangular:mainfrom
mmalerba:sf/number
Closed

feat(forms): support binding null to number input#66917
mmalerba wants to merge 7 commits intoangular:mainfrom
mmalerba:sf/number

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

@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Feb 12, 2026
@ngbot
Copy link

ngbot bot commented Feb 12, 2026

I see that you just added the action: merge label, but the following checks are still failing:
    failure status "google-internal-tests" is failing
    pending missing required labels: target: *
    pending 3 pending code reviews

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken main, please try rebasing to main and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@mmalerba mmalerba added target: minor This PR is targeted for the next minor release merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Feb 12, 2026
@mmalerba
Copy link
Contributor Author

mmalerba commented Feb 12, 2026

caretaker: passing tgp

@mmalerba mmalerba removed the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Feb 13, 2026
@mattrbeck
Copy link
Member

This PR was merged into the repository. The changes were merged into the following branches:

@mattrbeck mattrbeck closed this in 27397b3 Feb 13, 2026
mattrbeck pushed a commit that referenced this pull request Feb 13, 2026
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.

PR Close #66917
mattrbeck pushed a commit that referenced this pull request Feb 13, 2026
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"

PR Close #66917
mattrbeck pushed a commit that referenced this pull request Feb 13, 2026
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.

PR Close #66917
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: forms detected: feature PR contains a feature commit forms: signals target: minor This PR is targeted for the next minor release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants