diff --git a/src/utilities/formInputConfigs.js b/src/utilities/formInputConfigs.js index 3392e190e..40c0fc907 100644 --- a/src/utilities/formInputConfigs.js +++ b/src/utilities/formInputConfigs.js @@ -121,7 +121,7 @@ const FORM_INPUT_CONFIGS = seedObject => ({ }, [FORM_INPUT_KEYS.DATE_OF_BIRTH]: { type: FORM_INPUT_TYPES.DATE_OF_BIRTH, - initialValue: new Date(), + initialValue: '', key: 'dateOfBirth', invalidMessage: formInputStrings.must_be_a_date, isRequired: true, diff --git a/src/widgets/FormInputs/FormDOBInput.js b/src/widgets/FormInputs/FormDOBInput.js index 2a62ed9ab..d3a4b0c84 100644 --- a/src/widgets/FormInputs/FormDOBInput.js +++ b/src/widgets/FormInputs/FormDOBInput.js @@ -16,7 +16,7 @@ import { FormLabel } from './FormLabel'; import { FormInvalidMessage } from './FormInvalidMessage'; import { DATE_FORMAT } from '../../utilities/constants'; -const calculateAge = dob => `${Math.floor(moment().diff(dob, 'years', true))}`; +const calculateAge = dob => (!dob ? '' : `${Math.floor(moment().diff(dob, 'years', true))}`); const Action = { toggleDatePicker: 'toggleDatePicker', @@ -31,9 +31,9 @@ const Action = { const initialState = (seedDate, isValid) => ({ isValid, // If the date is a valid date datePickerOpen: false, - pickerValue: seedDate.toDate(), + pickerValue: seedDate?.toDate() || new Date(), ageValue: calculateAge(seedDate), - textInputValue: seedDate.format(DATE_FORMAT.DD_MM_YYYY), + textInputValue: seedDate ? seedDate.format(DATE_FORMAT.DD_MM_YYYY) : '', }); const reducer = (state, action) => { @@ -161,7 +161,7 @@ export const FormDOBInput = React.forwardRef( const [ { datePickerOpen, isValid, pickerValue, ageValue, textInputValue }, { toggleDatePicker, onPickDate, onTypeDate, onTypeAge }, - ] = useDobInput(moment(value ?? new Date()), onChangeDate, onValidate); + ] = useDobInput(value ? moment(value) : undefined, onChangeDate, onValidate); return ( <>