mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-06 12:43:06 +08:00
Fix date/time validations on item cards [SCI-10458]
This commit is contained in:
parent
7285156a8d
commit
830297fc70
1 changed files with 18 additions and 6 deletions
|
@ -100,6 +100,8 @@ export default {
|
|||
return this.i18n.t('repositories.item_card.repository_time_value.placeholder');
|
||||
case 'datetime':
|
||||
return this.i18n.t('repositories.item_card.repository_date_time_value.placeholder');
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
},
|
||||
viewPlaceholder() {
|
||||
|
@ -119,6 +121,8 @@ export default {
|
|||
return this.i18n.t('repositories.item_card.repository_date_time_range_value.no_date_time_range');
|
||||
}
|
||||
return this.i18n.t('repositories.item_card.repository_date_time_value.no_date_time');
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -132,17 +136,25 @@ export default {
|
|||
if (!(this.endDate instanceof Date)) this.update();
|
||||
},
|
||||
trimSecondsAndMilliseconds(date) {
|
||||
if (!date) return null;
|
||||
if (!(date instanceof Date)) return null;
|
||||
|
||||
if (this.mode === 'time') {
|
||||
return new Date().setHours(date.getHours(), date.getMinutes(), 0, 0);
|
||||
}
|
||||
|
||||
return date.setSeconds(0, 0);
|
||||
},
|
||||
validateValue() {
|
||||
this.error = null;
|
||||
const oldStart = this.trimSecondsAndMilliseconds(this.defaultStartDate);
|
||||
const oldEnd = this.trimSecondsAndMilliseconds(this.defaultEndDate);
|
||||
const newStart = this.trimSecondsAndMilliseconds(this.startDate);
|
||||
const newEnd = this.trimSecondsAndMilliseconds(this.endDate);
|
||||
// Date is not changed
|
||||
if (this.defaultStartDate && this.defaultEndDate) {
|
||||
if (this.trimSecondsAndMilliseconds(this.defaultStartDate) === this.trimSecondsAndMilliseconds(this.startDate)
|
||||
&& this.trimSecondsAndMilliseconds(this.defaultEndDate) === this.trimSecondsAndMilliseconds(this.endDate)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (oldEnd) {
|
||||
if (oldStart === newStart && oldEnd === newEnd) return false;
|
||||
} else if (oldStart === newStart) return false;
|
||||
|
||||
if (this.range) {
|
||||
// Both empty
|
||||
|
|
Loading…
Reference in a new issue