Skip to content

Commit

Permalink
fix(common): CHECKOUT-4336 Allow empty date custom field when optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Sanchez committed Sep 10, 2019
1 parent 7767400 commit 3e2401c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/app/address/getAddressValidationSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/app/address/mapAddressToFormValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3e2401c

Please sign in to comment.