From 9fc3289181d79fa83697c53cdb107db1f17ce19f Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Thu, 29 Feb 2024 15:43:02 -0800 Subject: [PATCH] i107: Don't error if the user enters a partial date range --- src/components/LuxDatePicker.vue | 6 +++++- tests/unit/specs/components/luxDatePicker.spec.js | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/components/LuxDatePicker.vue b/src/components/LuxDatePicker.vue index e98eefd..71ee63c 100644 --- a/src/components/LuxDatePicker.vue +++ b/src/components/LuxDatePicker.vue @@ -245,7 +245,7 @@ function updateInput(value) { } } function updateRangeInput(value) { - if (value.includes(" - ")) { + if (stringSeemsLikeDateRange(value)) { let r = value.split(" - ") if (isValidFormat(r[0]) && isValidFormat(r[1])) { if (!range.value) { @@ -268,6 +268,10 @@ function isValidFormat(d) { let date_regex = /^\d{1,2}\/\d{1,2}\/\d{4}$/ return date_regex.test(d) } + +function stringSeemsLikeDateRange(possibleRange) { + return possibleRange.includes(" - ") && !possibleRange.endsWith(" - ") +}