From fe365b60b52df4a612c853b43df18fa7f38cbc3d Mon Sep 17 00:00:00 2001 From: Keaton Lee Date: Fri, 1 Mar 2024 14:39:49 -0500 Subject: [PATCH 1/3] Allow a user to have a null date input. Devs will have to handle validation as they normal would with other controlls. --- packages/ui/src/components/va-date-input/VaDateInput.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/components/va-date-input/VaDateInput.vue b/packages/ui/src/components/va-date-input/VaDateInput.vue index 076ec67284..f5b030e4a4 100644 --- a/packages/ui/src/components/va-date-input/VaDateInput.vue +++ b/packages/ui/src/components/va-date-input/VaDateInput.vue @@ -263,10 +263,10 @@ const valueText = computed(() => { const onInputTextChanged = ({ target }: Event) => { if (props.disabled) { return } - const parsedValue = parseDateInputValue((target as HTMLInputElement).value) + const inputValue = (target as HTMLInputElement).value if (isValid.value) { - valueComputed.value = parsedValue + valueComputed.value = inputValue === '' ? null : parseDateInputValue(inputValue) } } From 1b4a0690b780f204f027abe869d24d52b5c4834b Mon Sep 17 00:00:00 2001 From: Keaton Lee Date: Thu, 23 May 2024 08:44:32 -0400 Subject: [PATCH 2/3] Updated to use props.clearValue and merged develop back in --- packages/ui/src/components/va-date-input/VaDateInput.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ui/src/components/va-date-input/VaDateInput.vue b/packages/ui/src/components/va-date-input/VaDateInput.vue index 26a3c2b544..efda793613 100644 --- a/packages/ui/src/components/va-date-input/VaDateInput.vue +++ b/packages/ui/src/components/va-date-input/VaDateInput.vue @@ -266,7 +266,7 @@ const onInputTextChanged = ({ target }: Event) => { const inputValue = (target as HTMLInputElement).value if (isValid.value) { - valueComputed.value = inputValue === '' ? null : parseDateInputValue(inputValue) + valueComputed.value = inputValue === '' ? props.clearValue : parseDateInputValue(inputValue) } } From 8fc6e12ba9b45fcd6cf5819e47997bbee13d86b2 Mon Sep 17 00:00:00 2001 From: Maksim Nedoshev Date: Fri, 24 May 2024 00:14:02 +0300 Subject: [PATCH 3/3] fix(date-input): allow null value --- .../components/va-date-input/VaDateInput.stories.ts | 13 +++++++++++++ .../ui/src/components/va-date-input/VaDateInput.vue | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/components/va-date-input/VaDateInput.stories.ts b/packages/ui/src/components/va-date-input/VaDateInput.stories.ts index 6b9985ee14..d5fe468b58 100644 --- a/packages/ui/src/components/va-date-input/VaDateInput.stories.ts +++ b/packages/ui/src/components/va-date-input/VaDateInput.stories.ts @@ -221,3 +221,16 @@ export const AsyncDate = () => ({ `, }) + +export const NullValue = () => ({ + components: { VaDateInput }, + data () { + return { + value: null, + } + }, + template: ` + [[value]]: {{ value === null ? 'null' : value }} + + `, +}) diff --git a/packages/ui/src/components/va-date-input/VaDateInput.vue b/packages/ui/src/components/va-date-input/VaDateInput.vue index efda793613..b26a0a3132 100644 --- a/packages/ui/src/components/va-date-input/VaDateInput.vue +++ b/packages/ui/src/components/va-date-input/VaDateInput.vue @@ -126,7 +126,7 @@ const props = defineProps({ ...useValidationProps as ValidationProps, ...useComponentPresetProp, - clearValue: { type: Date as PropType, default: undefined }, + clearValue: { type: undefined as unknown as PropType, default: undefined }, modelValue: { type: [Date, Array, Object, String, Number] as PropType }, resetOnClose: { type: Boolean, default: true }, @@ -239,7 +239,7 @@ const modelValueToString = (value: DateInputModelValue): string => { return '' } - throw new Error('VaDatePicker: Invalid model value. Value should be Date, Date[] or { start: Date, end: Date | null }, got ' + typeof value) + return '' } const {