Repository navigation
fix: prevent initial validation for date-picker when no constraints - #4169
Conversation
| */ | ||
| value: { | ||
| type: String, | ||
| observer: '_valueChanged', |
There was a problem hiding this comment.
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.
| this._toggleHasValue(!!newValue); | ||
|
|
||
| this._toggleHasValue(!!value); | ||
| if (oldSelectedDate !== newSelectedDate && newValue && oldValue !== undefined) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
web-components/packages/date-picker/src/vaadin-date-picker-mixin.js
Lines 703 to 705 in 2706287
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
When you clear the value, then _selectedDate is an empty string.
There was a problem hiding this comment.
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.
2706287 to
e589422
Compare
|
Kudos, SonarCloud Quality Gate passed!
|








Description
The PR prevents the initial validation that could previously take place when
date-pickerwas initially provided with a non-empty value and no constraints were specified.Part of #4150
Type of change
Checklist