From 88747b962aa54876087e0081ecb1641f8d35f8d7 Mon Sep 17 00:00:00 2001 From: Gykes <24581046+Gykes@users.noreply.github.com> Date: Thu, 27 Nov 2025 18:55:18 -0600 Subject: [PATCH] allow partial dates (#6333) --- ui/v2.5/src/locales/en-GB.json | 2 +- ui/v2.5/src/utils/yup.ts | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ui/v2.5/src/locales/en-GB.json b/ui/v2.5/src/locales/en-GB.json index e0f49aa3c..89ec4984c 100644 --- a/ui/v2.5/src/locales/en-GB.json +++ b/ui/v2.5/src/locales/en-GB.json @@ -1571,7 +1571,7 @@ "urls": "URLs", "validation": { "blank": "${path} must not be blank", - "date_invalid_form": "${path} must be in YYYY-MM-DD form", + "date_invalid_form": "${path} must be in YYYY, YYYY-MM, or YYYY-MM-DD form", "end_time_before_start_time": "End time must be greater than or equal to start time", "required": "${path} is a required field", "unique": "${path} must be unique" diff --git a/ui/v2.5/src/utils/yup.ts b/ui/v2.5/src/utils/yup.ts index e2c4987a8..5ae8123df 100644 --- a/ui/v2.5/src/utils/yup.ts +++ b/ui/v2.5/src/utils/yup.ts @@ -139,8 +139,22 @@ export function yupDateString(intl: IntlShape) { name: "date", test(value) { if (!value) return true; - if (!value.match(/^\d{4}-\d{2}-\d{2}$/)) return false; - if (Number.isNaN(Date.parse(value))) return false; + // Allow YYYY, YYYY-MM, or YYYY-MM-DD formats + if (!value.match(/^\d{4}(-\d{2}(-\d{2})?)?$/)) return false; + // Validate the date components + const parts = value.split("-"); + const year = parseInt(parts[0], 10); + if (year < 1 || year > 9999) return false; + if (parts.length >= 2) { + const month = parseInt(parts[1], 10); + if (month < 1 || month > 12) return false; + } + if (parts.length === 3) { + const day = parseInt(parts[2], 10); + if (day < 1 || day > 31) return false; + // Full date - validate it parses correctly + if (Number.isNaN(Date.parse(value))) return false; + } return true; }, message: intl.formatMessage({ id: "validation.date_invalid_form" }),