diff --git a/.gitignore b/.gitignore index 0a891c4a0..df836f391 100644 --- a/.gitignore +++ b/.gitignore @@ -74,3 +74,6 @@ typings/ !.yarn/releases !.yarn/sdks !.yarn/versions + +# vscode +.vscode/* \ No newline at end of file diff --git a/src/components/encounter/encounter-form-manager.ts b/src/components/encounter/encounter-form-manager.ts index 061745ff7..d25843dac 100644 --- a/src/components/encounter/encounter-form-manager.ts +++ b/src/components/encounter/encounter-form-manager.ts @@ -104,7 +104,7 @@ export class EncounterFormManager { function prepareObs(obsForSubmission: OpenmrsObs[], fields: FormField[]) { fields - .filter((field) => hasSubmitableObs(field)) + .filter((field) => hasSubmittableObs(field)) .forEach((field) => { if ((field.isHidden || field.isParentHidden) && field.meta.previousValue) { const valuesArray = Array.isArray(field.meta.previousValue) @@ -160,12 +160,10 @@ function addObsToList(obsList: Array>, obs: Partial = ({ ? [{ type: 'default' }, ...field.validators] : [{ type: 'default' }]; // handle validation - const basevalidatorConfig = { + const baseValidatorConfig = { expressionContext: { patient, mode: sessionMode }, values: { ...values, [fieldName]: value }, fields, @@ -519,13 +519,13 @@ const EncounterForm: React.FC = ({ const warnings = []; if (!isUnspecified) { for (let validatorConfig of validators) { - const errorsAndWarinings = - formFieldValidators[validatorConfig.type].validate(field, value, { - ...basevalidatorConfig, + const errorsAndWarnings = + formFieldValidators[validatorConfig.type]?.validate(field, value, { + ...baseValidatorConfig, ...validatorConfig, }) || []; - errors.push(...errorsAndWarinings.filter((error) => error.resultType == 'error')); - warnings.push(...errorsAndWarinings.filter((error) => error.resultType == 'warning')); + errors.push(...errorsAndWarnings.filter((error) => error.resultType == 'error')); + warnings.push(...errorsAndWarnings.filter((error) => error.resultType == 'warning')); } } setErrors?.(errors); diff --git a/src/components/repeat/repeat.component.tsx b/src/components/repeat/repeat.component.tsx index 85177baa4..7bb8b94ec 100644 --- a/src/components/repeat/repeat.component.tsx +++ b/src/components/repeat/repeat.component.tsx @@ -136,7 +136,7 @@ const Repeat: React.FC = ({ question, onChange, handler }) => { : null; }, [rows, fieldComponent]); - if (question.isHidden || !nodes) { + if (question.isHidden || !nodes || !hasVisibleField(question)) { return null; } return isGrouped ? ( @@ -150,6 +150,13 @@ const Repeat: React.FC = ({ question, onChange, handler }) => { ); }; +function hasVisibleField(field: FormField) { + if (field.questions?.length) { + return field.questions?.some((child) => !child.isHidden); + } + return !field.isHidden; +} + function getQuestionWithSupportedRendering(question: FormField) { return { ...question, diff --git a/src/registry/registry.ts b/src/registry/registry.ts index 71b10c4a2..25b9e08c3 100644 --- a/src/registry/registry.ts +++ b/src/registry/registry.ts @@ -94,7 +94,7 @@ export function registerExpressionHelper(name: string, fn: Function) { getFormsStore().expressionHelpers[name] = fn; } -export function registereformSchemaTransformers(registration: ComponentRegistration) { +export function registerFormSchemaTransformers(registration: ComponentRegistration) { const store = getFormsStore(); const existingIndex = store.formSchemaTransformers.findIndex((reg) => reg.name === registration.name); @@ -109,7 +109,7 @@ export function registereformSchemaTransformers(registration: ComponentRegistrat // Getters /** - * A convinience function that returns the appropriate control for a given rendering type. + * A convenience function that returns the appropriate control for a given rendering type. */ export async function getRegisteredControl(renderType: string) { if (registryCache.controls[renderType]) {