-
Notifications
You must be signed in to change notification settings - Fork 83
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
feat(date-picker): add unparsable-change event #6594
Conversation
} else if (this.__committedUnparsableValue !== this._unparsableValue) { | ||
result = true; | ||
this.validate(); | ||
this.dispatchEvent(new CustomEvent('unparsable-change')); |
There was a problem hiding this comment.
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 pass the unparseable value to event to allow handling with flow? This would reduce the need for additionals calls to __committedUnparsableValue or syncing it with the server for better (?) performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we've considered this option too, but in that case we will need to pass it also with the change
event. Note, the component fires change
rather than unparsable-change
when the user changes parsable input to unparsable and vice versa. So, ultimately, we come to the same outcome as with property synchronization in Flow. Both approaches seem to offer relatively similar performance: all the data is sent within a single round-trip – which is triggered by change or unparsable-change. Property synchronization appears to be more preferable, as it doesn't require changing the API of the change
event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understandable, but wouldn't that be a good change anyway? This would align the change event also to the change event from the normal inputs where you can access the value https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would align the change event also to the change event from the normal inputs where you can access the value
Just to make sure we understand each other, did you mean passing the input value via event.detail
or some other way? I'm not sure if the native change event does it this way. The native event provides access to the target element through which you can access the value, yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, dismiss my comment 😬 it's done by accessing the event.target.value instead of details
if (this.opened) { | ||
// Closing will implicitly select parsed or focused date | ||
this.close(); | ||
} else { | ||
this.__commitParsedOrFocusedDate(); | ||
} | ||
if (oldValue === this.value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: Now that the validation is the responsibility of the commit logic, we no longer need to trigger validation here, which fixes #6591.
0666023
to
60ea348
Compare
6e4f5cd
to
9cf2d1c
Compare
@@ -911,7 +957,6 @@ export const DatePickerMixin = (subclass) => | |||
} else { | |||
this.__keepInputValue = true; | |||
this.__commitDate(null); | |||
this._selectedDate = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: This line is unnecessary since the selected date is already updated by __commitDate(null)
.
note: The validation can now be triggered twice on |
update JSDoc improve naming
1f327e1
to
67a74e5
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
This ticket/PR has been released with Vaadin 24.3.0. |
Description
The PR introduces a new event
unparsable-change
todate-picker
. This event is fired when the user attempts to commit or clear input that the component has failed to parse as a date. This event is intended as a supplement to the change event, which means it will be fired only when there is no change event.Here is a table that illustrates which event is fired based on the nature of the value change:
The PR also prevents
date-picker
from validating on Enter if the input hasn't changed (related to #6591).Part of vaadin/flow-components#5537
Type of change