Skip to content

refactor: add methods to make setting invalid overridable - #4097

Merged
vursen merged 4 commits into
masterfrom
refactor/commit-validation-result
Jun 28, 2022
Merged

vursen merged 4 commits into
masterfrom
refactor/commit-validation-result

Conversation

@vursen

@vursen vursen commented Jun 27, 2022 •

Copy link
Copy Markdown
Contributor

Description

  • Added a protected method _shouldSetInvalid(invalid) that determines whether the invalid property should be updated to the given invalid state (by default: always true).
  • Added a protected method _setInvalid(invalid) that updates the invalid property to the given invalid state if it passes _shouldSetInvalid. This method is supposed to be used by the web components wherever they need to update invalid internally instead of manipulating the property directly.

The main purpose of _shouldSetInvalid is to make it possible later for Flow to prevent the web components from committing client-side validation success: the final decision on whether a component is valid will be made by the server.

Part of #4081

Type of change

  • Internal

Checklist

  • I have read the contribution guide: https://vaadin.com/docs-beta/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

@vursen vursen changed the title refactor: refactor: add protected methods for controlling validation result commitment Jun 27, 2022
@vursen vursen changed the title refactor: add protected methods for controlling validation result commitment refactor: add methods for controlling validation result commitment Jun 27, 2022
@vursen
vursen changed the base branch from master to feat/validated-event June 27, 2022 06:49
@vursen
vursen force-pushed the refactor/commit-validation-result branch 2 times, most recently from 4facd4e to 6118dde Compare June 27, 2022 07:12
@vursen
vursen force-pushed the feat/validated-event branch from 44d3a1a to 47a9219 Compare June 27, 2022 08:33
Base automatically changed from feat/validated-event to master June 27, 2022 09:00
@DiegoCardoso

Copy link
Copy Markdown
Contributor

The main purpose of _shouldCommitValidationResult is to make it possible for Flow to later prevent setting invalid to true on the client-side: only the server will decide when the validation is considered successful.

If I understood it correctly, it should be the other way around. The Flow counterpart should allow the web component to set invalid to true, but disallow it to set it back to false. (ping @yuriy-fix)

@vursen

vursen commented Jun 27, 2022 •

Copy link
Copy Markdown
Contributor Author

If I understood it correctly, it should be the other way around. The Flow counterpart should allow the web component to set invalid to true, but disallow it to set it back to false.

Ah, you are right 👍 . It is just a typo by the way. I corrected the description.

@vursen
vursen force-pushed the refactor/commit-validation-result branch from 6118dde to b087222 Compare June 27, 2022 09:25
@vursen vursen changed the title refactor: add methods for controlling validation result commitment refactor: add methods for controlling the validation result commitment Jun 27, 2022
@vursen
vursen force-pushed the refactor/commit-validation-result branch from b41eb21 to 7a71d4c Compare June 27, 2022 11:51
@vursen
vursen requested review from DiegoCardoso and yuriy-fix June 27, 2022 14:37
@vursen
vursen marked this pull request as ready for review June 27, 2022 14:38

@web-padawan web-padawan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it make sense to simplify method names e.g. _shouldSetInvalid() and _setInvalid() to better describe what they do?

@vursen

vursen commented Jun 27, 2022 •

Copy link
Copy Markdown
Contributor Author

Would it make sense to simplify method names e.g. _shouldSetInvalid() and _setInvalid() to better describe what they do?

My concern at the beginning was that this naming might be confusing especially when you override shouldSetInvalid and then anyway set invalid on your own, but now when I think about that again, I see that the alternative naming brings more overhead than solves anything.

So I agree to use more straightforward naming. 👍 This way it will be in line with setFocused() and shouldSetFocus().

@vursen
vursen force-pushed the refactor/commit-validation-result branch 2 times, most recently from 55a477a to 243acbf Compare June 28, 2022 05:23
@vursen
vursen force-pushed the refactor/commit-validation-result branch from 243acbf to 5c55014 Compare June 28, 2022 05:29
@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@vursen vursen changed the title refactor: add methods for controlling the validation result commitment refactor: add methods for controlling which invalid state can be set Jun 28, 2022
@vursen vursen changed the title refactor: add methods for controlling which invalid state can be set refactor: add methods for controlling setting the invalid state Jun 28, 2022

@DiegoCardoso DiegoCardoso left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have noticed that ErrorController implements setInvalid, but didn't check if it might affect the new behavior. Could you double check it?

@vursen
vursen removed the request for review from yuriy-fix June 28, 2022 08:22
@vursen
vursen requested a review from yuriy-fix June 28, 2022 08:23
@web-padawan

Copy link
Copy Markdown
Member

I have noticed that ErrorController implements setInvalid, but didn't check if it might affect the new behavior

The new method is actually in the ValidateMixin and it has nothing to do with controllers. Unlike mixins that wrap each other (and can override methods), controllers are separate objects that do not have this caveat.

@DiegoCardoso

Copy link
Copy Markdown
Contributor

The new method is actually in the ValidateMixin and it has nothing to do with controllers. Unlike mixins that wrap each other (and can override methods), controllers are separate objects that do not have this caveat.

Ah, right. I wasn't fully aware of the difference between mixins and controllers. Got it now, thanks.

@vursen vursen changed the title refactor: add methods for controlling setting the invalid state refactor: add methods to make setting invalid overridable Jun 28, 2022
@vursen
vursen merged commit fb1eb36 into master Jun 28, 2022
@vursen
vursen deleted the refactor/commit-validation-result branch June 28, 2022 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants