diff --git a/src/app/address/getAddressValidationSchema.ts b/src/app/address/getAddressValidationSchema.ts index 8254e1320f..dd378e09ef 100644 --- a/src/app/address/getAddressValidationSchema.ts +++ b/src/app/address/getAddressValidationSchema.ts @@ -63,7 +63,8 @@ export default memoize(function getAddressValidationSchema({ // Transform NaN values to undefined to avoid empty string (empty input) to fail date // validation when it's optional .strict(true) - .transform(value => value === '' ? undefined : value); + .nullable(true) + .transform(value => value === '' ? null : value); } else if (type === 'integer') { schema[name] = number() // Transform NaN values to undefined to avoid empty string (empty input) to fail number diff --git a/src/app/address/mapAddressToFormValues.ts b/src/app/address/mapAddressToFormValues.ts index 0ebaf9e353..055851d195 100644 --- a/src/app/address/mapAddressToFormValues.ts +++ b/src/app/address/mapAddressToFormValues.ts @@ -48,13 +48,13 @@ export default function mapAddressToFormValues(fields: FormField[], address?: Ad return values; } -function getValue(fieldType?: string, fieldValue?: string | string[] | number, defaultValue?: string): string | string[] | number | Date { +function getValue(fieldType?: string, fieldValue?: string | string[] | number, defaultValue?: string): string | string[] | number | Date | undefined { if (fieldValue === undefined || fieldValue === null) { return getDefaultValue(fieldType, defaultValue); } if (fieldType === DynamicFormFieldType.date && typeof fieldValue === 'string') { - return new Date(fieldValue); + return fieldValue ? new Date(fieldValue) : undefined; } return fieldValue;