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!: Only fire intermediate events when editing input with invalid text. #8054

Merged
merged 3 commits into from
May 3, 2024

Conversation

johnnesky
Copy link
Member

@johnnesky johnnesky commented Apr 26, 2024

The basics

The details

Resolves

Fixes #7966

Proposed Changes

This propagates the fireChangeEvent parameter to the doValueInvalid_ 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 from this.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 with this.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.

@johnnesky johnnesky requested a review from a team as a code owner April 26, 2024 23:57
@johnnesky johnnesky requested a review from maribethb April 26, 2024 23:57
@github-actions github-actions bot added breaking change Used to mark a PR or issue that changes our public APIs. PR: fix Fixes a bug and removed PR: fix Fixes a bug breaking change Used to mark a PR or issue that changes our public APIs. labels Apr 26, 2024
Copy link
Contributor

@maribethb maribethb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Can you add a section to the PR description that makes it clear to readers of the release notes why this is a breaking change and what they might need to do in response. Here's an example in another PR #7991

@maribethb
Copy link
Contributor

Also note that the angle tests may need to be updated in the rc/v11 branch of blockly-samples. They've already been deleted from the rc/v11 branch of core because the fields themselves were removed.

@github-actions github-actions bot added breaking change Used to mark a PR or issue that changes our public APIs. PR: fix Fixes a bug and removed PR: fix Fixes a bug breaking change Used to mark a PR or issue that changes our public APIs. labels May 3, 2024
@johnnesky
Copy link
Member Author

Thanks! I updated the description.

Actually I think the angle field tests in blockly-samples will be okay?

@johnnesky johnnesky merged commit 171befa into google:develop May 3, 2024
12 checks passed
@johnnesky johnnesky deleted the nesky_invalid_intermediate branch May 3, 2024 01:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Used to mark a PR or issue that changes our public APIs. PR: fix Fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

input fields fire change events on invalid input before change is committed
2 participants