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 input fires valueChanges twice. #36087
Conversation
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.
LGTM
- the linting failure is because you need to format the test file correctly. I setup my VS Code to autorun the clang formatter on every save, which sorts this out
- also it would be good if we were able to explain, in the commit message, why the
(change)
event can now be removed; it was obviously included originally for a reason...
I think this is the reason... #7557 (comment) |
According to this we still support IE9 - https://angular.io/guide/browser-support |
2da3d40
to
0b4908b
Compare
Hi @TidianeRolland, thanks for the PR! Could you please provide a bit more information on this change to help me understand the problem better? Currently we fire 2 events: one after typing in the input field (as a result of the I also started a g3 presubmit for blueprint and a global one (internal only links) to see if this change affects any targets in g3. Thank you. |
Hi @AndrewKushnir thanks for the reply! Yes, currently we fire 2 events: one after typing in the input field (as a result of the oninput event handler) and another one when the input field loses the focus (due to onchange event handler). Having both events fire at the same time is undesirable and I think having the onchange event trigger just when the input field loses the focus is also undesirable, according to this issue #12540. I noticed that we're triggering the change event only for Thanks for your help |
My understanding, although it may be lost in the annals of time - perhaps as far back as AngularJS, is that the extra handler was only added to support IE9, which appeared not to trigger the |
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.
Hi @TidianeRolland and @petebacondarwin,
Running global TAP indicated that there are few tests in g3 that rely on the change
event to be present, here is an example code (simplified) from test harness:
setTextValue(element, text) {
element.value = text;
const changeEvent = new Event('change');
element.dispatchEvent(changeEvent);
}
as a result, form control doesn't pick up an updated value. This is similar to the test that you've added as a part of this PR.
It can probably be refactored to trigger input
event instead, but that would require additional time and investigation. I'm marking this PR with the "breaking change" flag, since there might be other cases outside g3 with the same behavior/expectations.
@TidianeRolland I also looked at the original issue report and I think it'd be great to add one more test using Forms API that would replicate original problem (and make sure that only one event is fired), so I set the status of my review to "requested changes".
Thank you.
Thanks to @petebacondarwin for the tip on needing to test IE9 and @gkalpak for helping to test the demo. It appears that the |
What's the contract on the |
@atscott thanks for additional investigation! 👍 Just want to check if this problem only happens in IE9 or also present in IE10/11? Thank you. |
That's right - I was able to reproduce this missing |
@atscott it's really strange because I wasn't able to reproduce this bug using IE9 emulated in IE11 and IE9 on a Windows 7 machine. The input event was triggered |
@TidianeRolland, fwiw I was able to reproduce it using IE9 emulated in IE11 on Windows 10. |
@TidianeRolland can you confirm that backspace/cut does fire the input event for you in IE9? I find it curious that it's working for you but not for me or George. You can use the demo linked above to test this. |
I redid my tests. Backspace does not fire input event for emulated IE9. |
Thanks for retesting that. I'm adding the blocked label on this PR for now. @AndrewKushnir is adding an action item to discuss with the team what the plan is for IE9 support in the future. We'll get back to you with what can be done with this after the discussion. |
Hi @TidianeRolland - We discussed this issue today and decided that we can make this change and add a note in the breaking change on what devs can do if they want to maintain IE9 support. Please update your commit message to include in your footer:
|
fd0de03
to
2578b7a
Compare
Hi @atscott - It's done |
One of the internal tests failures took me down a deep rabbit hole. It appears that this change may also break some selenium-webdriver tests if you have an old version.
Still investigating what can be done to resolve this issue. |
2578b7a
to
1860e5f
Compare
Prior to this commit, number input fields would to fire valueChanges twice: once for `input` events when typing and second for the `change` event when the field lost focus (both events happen at once when using the increment and decrement buttons on the number field). Fixes angular#12540 BREAKING CHANGE: Number inputs no longer listen to the `change` event. * Tests which trigger `change` events need to be updated to trigger `input` events instead. * The `change` event was in place to support IE9, as we found that `input` events were not fired with backspace or cut actions. If you need to maintain IE9 support, you will need to add a change event listener to number inputs and call the `onChange` method of `NumberValueAccessor` manually. * Lastly, old versions of WebDriver would synthetically trigger the `change` event on `WebElement.clear` and `WebElement.sendKeys`. If you are using an old version of WebDriver, you may need to update tests to ensure `input` events are triggered. For example, you could use `element.sendKeys(Keys.chord(Keys.CONTROL, "a"), Keys.BACK_SPACE);` in place of `element.clear()`. PR Close angular#12540
1860e5f
to
f5cacbb
Compare
global presubmit from a few days ago with a rerun of the failing started today. These should all be green now. New TGP scheduled for the 12:00 train. |
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. |
Prior to this commit, number input fields would to fire valueChanges twice: once for `input` events when typing and second for the `change` event when the field lost focus (both events happen at once when using the increment and decrement buttons on the number field). Fixes angular#12540 BREAKING CHANGE: Number inputs no longer listen to the `change` event. * Tests which trigger `change` events need to be updated to trigger `input` events instead. * The `change` event was in place to support IE9, as we found that `input` events were not fired with backspace or cut actions. If you need to maintain IE9 support, you will need to add a change event listener to number inputs and call the `onChange` method of `NumberValueAccessor` manually. * Lastly, old versions of WebDriver would synthetically trigger the `change` event on `WebElement.clear` and `WebElement.sendKeys`. If you are using an old version of WebDriver, you may need to update tests to ensure `input` events are triggered. For example, you could use `element.sendKeys(Keys.chord(Keys.CONTROL, "a"), Keys.BACK_SPACE);` in place of `element.clear()`. PR Close angular#12540 PR Close angular#36087
Prior to this commit, input field of type number used to fire valueChanges twice. First time after typing in the input field and second time when the input field loses the focus.
PR Close #12540
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Input field of type number emits valueChanges twice. First time after typing in the input field and second time when the input field loses the focus.
Issue Number: #12540
What is the new behavior?
Input field of type number emits valueChanges once.
Does this PR introduce a breaking change?
Other information