fix(filter): don't prevent entering date math strings
Resolves https://community.vikunja.io/t/filter-setting-s/1791/2
This commit is contained in:
parent
7f279c98e1
commit
aa5e11915e
@ -75,6 +75,7 @@ import {useI18n} from 'vue-i18n'
|
||||
|
||||
import flatPickr from 'vue-flatpickr-component'
|
||||
import 'flatpickr/dist/flatpickr.css'
|
||||
import {parseDateOrString} from '@/helpers/time/parseDateOrString'
|
||||
|
||||
import Popup from '@/components/misc/popup.vue'
|
||||
import {DATE_RANGES} from '@/components/date/dateRanges'
|
||||
@ -120,9 +121,9 @@ watch(
|
||||
to.value = newValue.dateTo
|
||||
// Only set the date back to flatpickr when it's an actual date.
|
||||
// Otherwise flatpickr runs in an endless loop and slows down the browser.
|
||||
const dateFrom = new Date(from.value)
|
||||
const dateTo = new Date(to.value)
|
||||
if (dateTo.getTime() === dateTo.getTime() && dateFrom.getTime() === dateFrom.getTime()) {
|
||||
const dateFrom = parseDateOrString(from.value, false)
|
||||
const dateTo = parseDateOrString(to.value, false)
|
||||
if (dateFrom instanceof Date && dateTo instanceof Date) {
|
||||
flatpickrRange.value = `${from.value} to ${to.value}`
|
||||
}
|
||||
},
|
||||
|
@ -1,8 +1,12 @@
|
||||
export function parseDateOrString(rawValue: string | undefined, fallback: unknown) {
|
||||
if (typeof rawValue === 'undefined') {
|
||||
export function parseDateOrString(rawValue: string | undefined | null, fallback: unknown): (unknown | string | Date) {
|
||||
if (rawValue === null || typeof rawValue === 'undefined') {
|
||||
return fallback
|
||||
}
|
||||
|
||||
if (rawValue.toLowerCase().includes('now') || rawValue.toLowerCase().includes('||')) {
|
||||
return rawValue
|
||||
}
|
||||
|
||||
const d = new Date(rawValue)
|
||||
|
||||
return !isNaN(+d)
|
||||
|
Loading…
x
Reference in New Issue
Block a user