diff --git a/src/core_modules/capture-core/components/D2Form/D2SectionFields.container.js b/src/core_modules/capture-core/components/D2Form/D2SectionFields.container.js index 0ce87af445..39bfcce74b 100644 --- a/src/core_modules/capture-core/components/D2Form/D2SectionFields.container.js +++ b/src/core_modules/capture-core/components/D2Form/D2SectionFields.container.js @@ -16,7 +16,7 @@ const makeMapStateToProps = () => { const getRulesMessages = makeGetMessages(); const getCompulsory = makeGetCompulsory(); const getDisabled = makeGetDisabled(); - const mapStateToProps = (state: Object, props: { formId: string }) => ({ + const mapStateToProps = (state: Object, props: { formId: string, fieldsMetaData: any }) => ({ values: getSectionValues(state, props), rulesHiddenFields: getHiddenFields(state, props), rulesMessages: getRulesMessages(state, props), 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 2cad7557fd..b6aaf32d5c 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 @@ -89,7 +89,7 @@ export type FieldCommitOptions = {| errorCode?: string, |}; -type FieldCommitOptionsExtended = {| +export type FieldCommitOptionsExtended = {| ...FieldCommitOptions, plugin?: ?boolean, |}; @@ -171,12 +171,12 @@ export class FormBuilder extends React.Component { let validationData; try { const { validators } = field; - validationData = await validateValue( + validationData = await validateValue({ validators, - values[field.id], + value: values[field.id], validationContext, - handleIsValidatingInternal, - ); + postProcessAsyncValidatonInitiation: handleIsValidatingInternal, + }); } catch (reason) { if (reason && isObject(reason) && reason.isCanceled) { validationData = null; @@ -405,14 +405,13 @@ export class FormBuilder extends React.Component { errorMessage: options.error, errorType: validatorTypes.TYPE_BASE, errorData: undefined }) : - (await validateValue( + (await validateValue({ validators, value, - onGetValidationContext && onGetValidationContext(), - handleIsValidatingInternal, - // $FlowFixMe - options, - ) + validationContext: onGetValidationContext && onGetValidationContext(), + postProcessAsyncValidatonInitiation: handleIsValidatingInternal, + commitOptions: options, + }) // $FlowFixMe[prop-missing] automated comment .then(({ valid, errorMessage, errorType, errorData }) => { updateField({ valid, errorMessage, errorType, errorData }); diff --git a/src/core_modules/capture-core/components/D2Form/FormBuilder/index.js b/src/core_modules/capture-core/components/D2Form/FormBuilder/index.js index 58c5e95c43..fab5ff84f6 100644 --- a/src/core_modules/capture-core/components/D2Form/FormBuilder/index.js +++ b/src/core_modules/capture-core/components/D2Form/FormBuilder/index.js @@ -1,4 +1,4 @@ // @flow export { FormBuilder } from './FormBuilder.component'; export type { PostProcessErrorMessage, ErrorData } from './formbuilder.types'; -export type { FieldConfig, FieldCommitOptions } from './FormBuilder.component'; +export type { FieldConfig, FieldCommitOptionsExtended } from './FormBuilder.component'; diff --git a/src/core_modules/capture-core/components/D2Form/index.js b/src/core_modules/capture-core/components/D2Form/index.js index 854c2f82c9..8117978a25 100644 --- a/src/core_modules/capture-core/components/D2Form/index.js +++ b/src/core_modules/capture-core/components/D2Form/index.js @@ -1,4 +1,4 @@ // @flow export { asyncHandlerActionTypes, asyncUpdateFieldEpic } from './asyncHandlerHOC'; export { D2Form } from './D2Form.container'; -export type { FieldCommitOptions } from './FormBuilder'; +export type { FieldCommitOptionsExtended } from './FormBuilder'; diff --git a/src/core_modules/capture-core/rules/validateAssignEffects.js b/src/core_modules/capture-core/rules/validateAssignEffects.js index 183bee1e42..62f71694d7 100644 --- a/src/core_modules/capture-core/rules/validateAssignEffects.js +++ b/src/core_modules/capture-core/rules/validateAssignEffects.js @@ -42,7 +42,7 @@ export const validateAssignEffects = async ({ const validationContext = onGetValidationContext && onGetValidationContext(); try { - const validatorResult = await validateValue(validators, value, validationContext); + const validatorResult = await validateValue({ validators, value, validationContext }); const effectWithValidation = Object.assign({}, effectsForId[lastIndex], validatorResult); acc[metaData.id] = [effectWithValidation]; diff --git a/src/core_modules/capture-core/utils/validation/validateValue.js b/src/core_modules/capture-core/utils/validation/validateValue.js index 8ef0ed0eaa..c91bf08fda 100644 --- a/src/core_modules/capture-core/utils/validation/validateValue.js +++ b/src/core_modules/capture-core/utils/validation/validateValue.js @@ -1,6 +1,6 @@ // @flow import type { ValidatorContainer } from './getValidators'; -import type { FieldCommitOptions } from '../../components/D2Form'; +import type { FieldCommitOptionsExtended } from '../../components/D2Form'; export type Validations = { valid: boolean, @@ -9,13 +9,19 @@ export type Validations = { errorData?: Object, }; -export const validateValue = async ( +export const validateValue = async ({ + validators, + value, + validationContext, + postProcessAsyncValidatonInitiation, + commitOptions, +}: { validators?: Array, value: any, validationContext: ?Object, - postProcessAsyncValidatonInitiation: ?Function, - commitOptions?: ?FieldCommitOptions, -): Promise => { + postProcessAsyncValidatonInitiation?: Function, + commitOptions?: ?FieldCommitOptionsExtended, +}): Promise => { if (!validators || validators.length === 0) { return { valid: true,