-
Notifications
You must be signed in to change notification settings - Fork 25.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(forms): number inputs should report null when blank #8141
Conversation
@@ -35,7 +35,7 @@ export class NumberValueAccessor implements ControlValueAccessor { | |||
} | |||
|
|||
registerOnChange(fn: (_: number) => void): void { | |||
this.onChange = (value) => { fn(NumberWrapper.parseFloat(value)); }; | |||
this.onChange = (value) => { fn(value == '' ? null : NumberWrapper.parseFloat(value)); }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the value is 0
then value == ''
will also be true. Using ===
instead would fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value reported comes from the HTML element, so it will always be a string ('0'
not 0
). Because of that, '0'
won't be ==
to ''
. We could use looseIdentity
from the Dart facade (===
won't work with Dart), but not sure it's necessary in this case.
That said, I should probably add the '0' case to one of the tests. Thanks for pointing it out :-)
Merging PR #8141 on behalf of @robertmesserle to branch presubmit-robertmesserle-pr-8141. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Fixes #6932