fix!: Only fire intermediate events when editing input with invalid text. #8054
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The basics
The details
Resolves
Fixes #7966
Proposed Changes
This propagates the
fireChangeEvent
parameter to thedoValueInvalid_
method, and uses it to conditionally inhibit the default behavior of firing a block change event when a field is assigned an invalid value.I also made a significant change to the way
doValueInvalid_
reverts the field value. Previously, it copied the value fromthis.htmlInput_!.getAttribute('data-untyped-default-value')
, which is always a string value. However, this doesn't really make sense for number fields, which usually contain a numerical value even when editing the associated text input widget. I replaced it withthis.valueWhenEditorWasOpened_
which is the exact value the field used to have.Finally, I conditionally skip firing the block change event if the new (reverted) value was the same as the value was before the most recent (invalid) edit.
The intermediate field change events were already being fired correctly (in addition to the incorrect block change events) so I didn't need to change that.
Reason for Changes
Test Coverage
I updated some existing unit tests to expect numerical values for numerical fields instead of string values when the validator returns null. I guess this is technically a breaking change.
Documentation
N/A
Additional Information
N/A
Breaking changes / To fix
This affects the data type assigned to a field's value when an invalid value is provided.
When a user selects a number field and types letters instead of numbers, the attempt to set the field's value to the user's input will fail, and instead the internal value of the field will be reset to what it used to be before the user started to edit it. However, the value assigned to the field in this case used to be a string containing numerals instead of the actual original number, whereas after this change the original number will be assigned instead.