Browse Source

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 <fenn25.fn@gmail.com>
pull/52364/head
nfebe 7 months ago
committed by Ferdinand Thiessen
parent
commit
3c73f3fcae
  1. 9
      apps/files_sharing/src/components/SharingEntryLink.vue
  2. 9
      apps/files_sharing/src/mixins/SharesMixin.js

9
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">
<template #icon>
<IconCalendarBlank :size="20" />
</template>
@ -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
},
/**

9
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)
},
/**

Loading…
Cancel
Save