diff --git a/src/components/form/Submit.tsx b/src/components/form/Submit.tsx index bb9514db..443d563d 100644 --- a/src/components/form/Submit.tsx +++ b/src/components/form/Submit.tsx @@ -57,9 +57,9 @@ const Submit: React.FC = (props) => { const sectionsArray = templateData.widget[visited].sections; return ( - + {sectionsArray?.map((section: string) => ( - + {sections?.[section]?.questions?.map((question: string) => { const answer = data.widgetContext[visited].sectionContext[section].questionContext[ diff --git a/src/components/form/components/DateInput.tsx b/src/components/form/components/DateInput.tsx index 9cb9e0ba..0fc4925e 100644 --- a/src/components/form/components/DateInput.tsx +++ b/src/components/form/components/DateInput.tsx @@ -15,6 +15,7 @@ import { BUSINESS_DATE_FORMAT, DefaultPickerModeVisibleFormatMapping, IDateTimePickerMode, + dateFormat, } from '../../../../RN-UI-LIB/src/utlis/dates'; interface IDateInput { @@ -42,7 +43,6 @@ const DateInput: React.FC = (props) => { } const handleChange = (text: string, onChange: (...event: any[]) => void) => { - console.log('text', text); addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.AV_FORM_ELEMENT_CHANGED, { caseId, questionType, @@ -71,27 +71,42 @@ const DateInput: React.FC = (props) => { validate: (data) => validateInput(data, { required: { ...question.metadata.validators?.required }, - [Validators.PATTERN]: { - value: - /(^(((0[1-9]|1[0-9]|2[0-8])[-](0[1-9]|1[012]))|((29|30|31)[-](0[13578]|1[02]))|((29|30)[-](0[4,6,9]|11)))[-](19|[2-9][0-9])\d\d$)|(^29[-]02[-](19|[2-9][0-9])(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)$)/, - message: `Please enter correct date, in format of ${ - DefaultPickerModeVisibleFormatMapping[IDateTimePickerMode.DATE] - }`, - }, + [Validators.PATTERN]: question.metadata.validators?.required + ? { + value: + /(^(((0[1-9]|1[0-9]|2[0-8])[-](0[1-9]|1[012]))|((29|30|31)[-](0[13578]|1[02]))|((29|30)[-](0[4,6,9]|11)))[-](19|[2-9][0-9])\d\d$)|(^29[-]02[-](19|[2-9][0-9])(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)$)/, + message: `Please enter correct date, in format of ${ + DefaultPickerModeVisibleFormatMapping[IDateTimePickerMode.DATE] + }`, + } + : null, [Validators.MAX_TODAY]: { ...question.metadata.validators?.[Validators.MAX_TODAY] }, [Validators.MIN_TODAY]: { ...question.metadata.validators?.[Validators.MIN_TODAY] }, }), }} - render={({ field: { onChange } }) => ( - handleChange(text, onChange)} - outputFormat="DD-MM-YYYY" - /> - )} + render={({ field: { onChange, value } }) => { + let dateString = value?.answer; + if (dateString) { + const parts = dateString.split('-'); + const day = parts[0]; + const month = parts[1]; + const year = parts[2]; + + const date = new Date(`${year}-${month}-${day}`); + dateString = date.toString(); + } + return ( + handleChange(text, onChange)} + outputFormat="DD-MM-YYYY" + /> + ); + }} name={`widgetContext.${widgetId}.sectionContext.${props.sectionId}.questionContext.${questionId}`} /> = (props) => { {currentCase.phoneNumbers?.map((phoneNumber, index) => { return ( = (props) => { validate: (data) => validateInput(data, { required: { ...question.metadata.validators?.required }, - [Validators.PATTERN]: { - value: /^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/, - message: `Please enter correct time, in format of ${ - DefaultPickerModeVisibleFormatMapping[IDateTimePickerMode.TIME] - }`, - }, + [Validators.PATTERN]: question.metadata.validators?.required + ? { + value: /^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/, + message: `Please enter correct time, in format of ${ + DefaultPickerModeVisibleFormatMapping[IDateTimePickerMode.TIME] + }`, + } + : null, }), }} - render={({ field: { onChange, value } }) => ( - { - handleChange(text, onChange); - }} - /> - )} + render={({ field: { onChange, value } }) => { + return ( + { + handleChange(text, onChange); + }} + /> + ); + }} name={`widgetContext.${widgetId}.sectionContext.${props.sectionId}.questionContext.${questionId}`} /> = ({ Select payment date