From 3c73f3fcae70c399bafb132885e0768019ee5847 Mon Sep 17 00:00:00 2001 From: nfebe Date: Wed, 23 Apr 2025 01:07:29 +0100 Subject: [PATCH] fix(files_sharing): Improve expiration date input change handling If the time picker component is emitting a Date object already, then there is redundant call of `new Date(new Date())` and therefore introduces subtle bugs, for example on chrome users could not enter expiration date with keyboard. - Use @update:model-value instead of @change/@input for more reliable date updates - Ensure null and invalid dates are handled correctly in onExpirationChange - Validate date input before updating defaultExpirationDateEnabled Resolves : https://github.com/nextcloud/server/issues/51875 Signed-off-by: nfebe --- apps/files_sharing/src/components/SharingEntryLink.vue | 9 +++++---- apps/files_sharing/src/mixins/SharesMixin.js | 9 +++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/files_sharing/src/components/SharingEntryLink.vue b/apps/files_sharing/src/components/SharingEntryLink.vue index 2c19afd1dca..781626a1ec9 100644 --- a/apps/files_sharing/src/components/SharingEntryLink.vue +++ b/apps/files_sharing/src/components/SharingEntryLink.vue @@ -108,7 +108,8 @@ type="date" :min="dateTomorrow" :max="maxExpirationDateEnforced" - @change="expirationDateChanged($event)"> + @update:model-value="onExpirationChange" + @change="expirationDateChanged"> @@ -874,9 +875,9 @@ export default { }, expirationDateChanged(event) { - const date = event.target.value - this.onExpirationChange(date) - this.defaultExpirationDateEnabled = !!date + const value = event?.target?.value + const isValid = !!value && !isNaN(new Date(value).getTime()) + this.defaultExpirationDateEnabled = isValid }, /** diff --git a/apps/files_sharing/src/mixins/SharesMixin.js b/apps/files_sharing/src/mixins/SharesMixin.js index 7d0d0dbb59b..c5bad91314e 100644 --- a/apps/files_sharing/src/mixins/SharesMixin.js +++ b/apps/files_sharing/src/mixins/SharesMixin.js @@ -234,8 +234,13 @@ export default { * @param {Date} date */ onExpirationChange(date) { - const formattedDate = date ? this.formatDateToString(new Date(date)) : '' - this.share.expireDate = formattedDate + if (!date) { + this.share.expireDate = null + this.$set(this.share, 'expireDate', null) + return + } + const parsedDate = (date instanceof Date) ? date : new Date(date) + this.share.expireDate = this.formatDateToString(parsedDate) }, /**