Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

kara
Copy link
Contributor

@kara kara commented Apr 19, 2016

Fixes #6932

@kara kara added the action: review The PR is still awaiting reviews from at least one requested reviewer label Apr 19, 2016
@vsavkin vsavkin added pr_state: LGTM and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Apr 19, 2016
@vsavkin vsavkin assigned kara and unassigned vsavkin Apr 19, 2016
@kara kara added the action: merge The PR is ready for merge by the caretaker label Apr 19, 2016
@@ -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)); };

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.

Copy link
Contributor Author

@kara kara Apr 20, 2016

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 :-)

@mary-poppins
Copy link

Merging PR #8141 on behalf of @robertmesserle to branch presubmit-robertmesserle-pr-8141.

@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 Sep 8, 2019
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 cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

required validator does not work with number
6 participants