diff --git a/i18n/en.pot b/i18n/en.pot index 51d2f1bcc6..0b3035d728 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -5,8 +5,8 @@ msgstr "" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1)\n" -"POT-Creation-Date: 2024-11-04T14:40:30.714Z\n" -"PO-Revision-Date: 2024-11-04T14:40:30.715Z\n" +"POT-Creation-Date: 2024-11-07T20:29:15.378Z\n" +"PO-Revision-Date: 2024-11-07T20:29:15.379Z\n" msgid "Choose one or more dates..." msgstr "Choose one or more dates..." diff --git a/src/core_modules/capture-core/components/D2Form/FormBuilder/FormBuilder.component.js b/src/core_modules/capture-core/components/D2Form/FormBuilder/FormBuilder.component.js index d18ce971f8..eb257e5f5e 100644 --- a/src/core_modules/capture-core/components/D2Form/FormBuilder/FormBuilder.component.js +++ b/src/core_modules/capture-core/components/D2Form/FormBuilder/FormBuilder.component.js @@ -126,7 +126,7 @@ export class FormBuilder extends React.Component { .reduce(async (passPromise, currentValidator) => { const pass = await passPromise; if (pass === true) { - let result = currentValidator.validator(value, validationContext, + let result = currentValidator.validator(value, { error: commitOptions?.error, errorCode: commitOptions?.errorCode }); if (result instanceof Promise) { result = onIsValidatingInternal ? diff --git a/src/core_modules/capture-core/components/D2Form/field/validators/getValidators.js b/src/core_modules/capture-core/components/D2Form/field/validators/getValidators.js index fbf18831a8..f7d4b3b869 100644 --- a/src/core_modules/capture-core/components/D2Form/field/validators/getValidators.js +++ b/src/core_modules/capture-core/components/D2Form/field/validators/getValidators.js @@ -118,7 +118,7 @@ const validatorsForTypes = { type: validatorTypes.TYPE_BASE, }, { - validator: (value: string, allowFutureDate) => (allowFutureDate ? true : isValidNonFutureDate(value)), + validator: isValidNonFutureDate, type: validatorTypes.TYPE_EXTENDED, message: errorMessages.DATE_FUTURE_NOT_ALLOWED, }], @@ -212,14 +212,14 @@ function buildTypeValidators(metaData: DataElement | DateDataElement): ?Array ({ ...validatorContainer, - validator: (value: any, validationContext: ?Object, internalComponentError: ?Object) => { + validator: (value: any, internalComponentError: ?Object) => { if (!value && value !== 0 && value !== false) { return true; } const toValidateValue = isString(value) ? value.trim() : value; // $FlowFixMe dataElementTypes flow error - return validatorContainer.validator(toValidateValue, metaData.allowFutureDate, internalComponentError); + return validatorContainer.validator(toValidateValue, internalComponentError); }, })); diff --git a/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/DataEntryWrapper/DataEntry/fieldValidators/eventDate.validatorContainersGetter.js b/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/DataEntryWrapper/DataEntry/fieldValidators/eventDate.validatorContainersGetter.js index 4656b2fe09..1bebc75542 100644 --- a/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/DataEntryWrapper/DataEntry/fieldValidators/eventDate.validatorContainersGetter.js +++ b/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/DataEntryWrapper/DataEntry/fieldValidators/eventDate.validatorContainersGetter.js @@ -8,7 +8,7 @@ const preValidateDate = (value?: ?string, internalError?: ?Object) => { return true; } - return isValidDate(value, null, internalError); + return isValidDate(value, internalError); }; export const getEventDateValidatorContainers = () => { diff --git a/src/core_modules/capture-core/components/DataEntry/dataEntryField/internal/dataEntryField.utils.js b/src/core_modules/capture-core/components/DataEntry/dataEntryField/internal/dataEntryField.utils.js index 20beb72793..f481697cb3 100644 --- a/src/core_modules/capture-core/components/DataEntry/dataEntryField/internal/dataEntryField.utils.js +++ b/src/core_modules/capture-core/components/DataEntry/dataEntryField/internal/dataEntryField.utils.js @@ -22,7 +22,7 @@ export function getValidationError(value: any, validatorContainers: ?Array { - const { isValid, momentDate } = parseDate(value); - - if (!isValid) { - return isValid; +export const isValidNonFutureDate = (value: string, internalComponentError) => { + if (internalComponentError && internalComponentError?.errorCode === 'INVALID_DATE_MORE_THAN_MAX') { + return { + valid: !internalComponentError.error, + errorMessage: CUSTOM_VALIDATION_MESSAGES.INVALID_DATE_MORE_THAN_MAX, + }; } - - return { - // $FlowFixMe -> if parseDate returns isValid true, there should always be a momentDate - valid: momentDate.isSameOrBefore(moment()), - errorMessage: CUSTOM_VALIDATION_MESSAGES.INVALID_DATE_MORE_THAN_MAX, - }; + return true; };