@openmrs/esm-form-engine-lib 2.1.0-pre.1597 → 2.1.0-pre.1604
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
@@ -46,6 +46,7 @@ export const FormFieldRenderer = ({ fieldId, valueAdapter, repeatOptions }: Form
|
|
46
46
|
formFieldValidators,
|
47
47
|
addInvalidField,
|
48
48
|
removeInvalidField,
|
49
|
+
updateFormField,
|
49
50
|
} = context;
|
50
51
|
|
51
52
|
const fieldValue = useWatch({ control, name: fieldId, exact: true });
|
@@ -132,6 +133,18 @@ export const FormFieldRenderer = ({ fieldId, valueAdapter, repeatOptions }: Form
|
|
132
133
|
}
|
133
134
|
setWarnings(validationWarnings);
|
134
135
|
handleFieldLogic(field, context);
|
136
|
+
if (field.meta.groupId) {
|
137
|
+
const group = formFields.find((f) => f.id === field.meta.groupId);
|
138
|
+
if (group) {
|
139
|
+
group.questions = group.questions.map((child) => {
|
140
|
+
if (child.id === field.id) {
|
141
|
+
return field;
|
142
|
+
}
|
143
|
+
return child;
|
144
|
+
});
|
145
|
+
updateFormField(group);
|
146
|
+
}
|
147
|
+
}
|
135
148
|
};
|
136
149
|
|
137
150
|
if (!inputComponentWrapper) {
|
package/src/form-engine.test.tsx
CHANGED
@@ -877,6 +877,49 @@ describe('Form engine component', () => {
|
|
877
877
|
});
|
878
878
|
|
879
879
|
describe('Obs group', () => {
|
880
|
+
it('should save obs group on form submission', async () => {
|
881
|
+
const saveEncounterMock = jest.spyOn(api, 'saveEncounter');
|
882
|
+
await act(async () => {
|
883
|
+
renderForm(null, obsGroupTestForm);
|
884
|
+
});
|
885
|
+
|
886
|
+
// Fill out the obs group fields
|
887
|
+
const dateOfBirth = screen.getByRole('textbox', { name: /date of birth/i });
|
888
|
+
const maleRadio = screen.getByRole('radio', { name: /^male$/i });
|
889
|
+
|
890
|
+
await user.click(dateOfBirth);
|
891
|
+
await user.paste('2020-09-09T00:00:00.000Z');
|
892
|
+
await user.click(maleRadio);
|
893
|
+
|
894
|
+
// Submit the form
|
895
|
+
await user.click(screen.getByRole('button', { name: /save/i }));
|
896
|
+
|
897
|
+
// Verify the encounter was saved with the correct structure
|
898
|
+
expect(saveEncounterMock).toHaveBeenCalledTimes(1);
|
899
|
+
|
900
|
+
const [_, encounter] = saveEncounterMock.mock.calls[0];
|
901
|
+
expect(encounter.obs.length).toBe(1);
|
902
|
+
expect(encounter.obs[0]).toEqual({
|
903
|
+
groupMembers: [
|
904
|
+
{
|
905
|
+
value: '1534AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
906
|
+
concept: '1587AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
907
|
+
formFieldNamespace: 'rfe-forms',
|
908
|
+
formFieldPath: 'rfe-forms-childSex',
|
909
|
+
},
|
910
|
+
{
|
911
|
+
value: '2020-09-09',
|
912
|
+
concept: '164802AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
913
|
+
formFieldNamespace: 'rfe-forms',
|
914
|
+
formFieldPath: 'rfe-forms-birthDate',
|
915
|
+
},
|
916
|
+
],
|
917
|
+
concept: '1c70c490-cafa-4c95-9fdd-a30b62bb78b8',
|
918
|
+
formFieldNamespace: 'rfe-forms',
|
919
|
+
formFieldPath: 'rfe-forms-myGroup',
|
920
|
+
});
|
921
|
+
});
|
922
|
+
|
880
923
|
it('should test addition of a repeating group', async () => {
|
881
924
|
await act(async () => {
|
882
925
|
renderForm(null, obsGroupTestForm);
|