Skip to content

fix: prevent initial validation for date-picker when no constraints - #4169

Merged
DiegoCardoso merged 5 commits into
masterfrom
fix/date-picker/prevent-initial-validation
Jul 14, 2022
Merged

DiegoCardoso merged 5 commits into
masterfrom
fix/date-picker/prevent-initial-validation

Conversation

@vursen

@vursen vursen commented Jul 11, 2022 •

Copy link
Copy Markdown
Contributor

Description

The PR prevents the initial validation that could previously take place when date-picker was initially provided with a non-empty value and no constraints were specified.

Part of #4150

Type of change

  • Bugfix

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.

*/
value: {
type: String,
observer: '_valueChanged',

@vursen vursen Jul 11, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

note: Removed as otherwise Polymer always triggers the second _valueChanged call. It is weird but Polymer seems to trigger observers as many times as they are declared in the chain of the prototypes even if the observer method remains the same. Note, in the case of _valueChanged, it is also declared in InputMixin.

@vursen vursen changed the title fix!: prevent initial validation for date-picker fix: prevent initial validation for date-picker Jul 12, 2022
@vursen vursen changed the title fix: prevent initial validation for date-picker fix: prevent initial validation for date-picker when no constraints Jul 12, 2022
this._toggleHasValue(!!newValue);

this._toggleHasValue(!!value);
if (oldSelectedDate !== newSelectedDate && newValue && oldValue !== undefined) {

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.

Isn't oldSelectedDate !== newSelectedDate always be truth-y? When _selectedDate is an instance of Date, then the comparison is always true. The other moment I found where _selectedDate is not a Date is when you change the value from something to empty value. On that case, oldSelectedDate is null and newSelectedDate is ''. Am I missing something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Isn't oldSelectedDate !== newSelectedDate always be truth-y?

There is a check before updating the selected date to avoid creating a new instance of Date if the date hasn't actually changed:

if (!dateEquals(this[property], date)) {
this[property] = date;
}

@vursen vursen Jul 12, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The other moment I found where _selectedDate is not a Date is when you change the value from something to empty value. On that case, oldSelectedDate is null and newSelectedDate is ''

Not sure I understand what the case are we talking about here. Setting an empty value via the value property? Or something else?

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.

There is a check before updating the selected date to avoid creating a new instance of Date if the date hasn't actually changed

Ah, right. I missed that.

Not sure I understand what the case are we talking about here. Setting an empty value via the value property? Or something else?

I was actually interacting with the element itself, not through the API. But I could double-check that the check is correct, given the current test case we have on the component.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was actually interacting with the element itself, not through the API. But I could double-check that the check is correct, given the current test case we have on the component.

Could you share the scenario to reproduce the problem?

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.

When you clear the value, then _selectedDate is an empty string.

@vursen vursen Jul 13, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, now I see.

The fact that _selectedDate can be an empty string doesn't seem to cause any issues at the moment but I agree that it is not perfect and can potentially lead to a bug, so here is a PR that corrects this behavior: #4187. Please, take a look.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rebased the PR.

@vursen
vursen force-pushed the fix/date-picker/prevent-initial-validation branch from 2706287 to e589422 Compare July 13, 2022 14:56
@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

@DiegoCardoso
DiegoCardoso merged commit 90b6daa into master Jul 14, 2022
@DiegoCardoso
DiegoCardoso deleted the fix/date-picker/prevent-initial-validation branch July 14, 2022 09:06
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