@openmrs/esm-form-engine-lib 2.1.0-pre.1584 → 2.1.0-pre.1585
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/083bcecacf9ae0b3/083bcecacf9ae0b3.gz +0 -0
- package/1bdd6eb63dcfc148/1bdd6eb63dcfc148.gz +0 -0
- package/5a22470d28efd31b/5a22470d28efd31b.gz +0 -0
- package/bfdd668cd7e4ec20/bfdd668cd7e4ec20.gz +0 -0
- package/package.json +1 -1
- package/src/components/inputs/text/text.component.tsx +3 -1
- package/src/components/inputs/text/text.test.tsx +3 -9
- package/src/components/renderer/form/form-renderer.component.tsx +0 -1
- package/src/components/repeat/helpers.ts +1 -0
- package/src/components/repeat/repeat.component.tsx +12 -8
- package/src/hooks/useFormStateHelpers.ts +18 -3
Binary file
|
Binary file
|
Binary file
|
Binary file
|
package/package.json
CHANGED
@@ -42,7 +42,9 @@ const TextField: React.FC<FormFieldInputProps> = ({ field, value, errors, warnin
|
|
42
42
|
<TextInput
|
43
43
|
id={field.id}
|
44
44
|
labelText={<FieldLabel field={field} />}
|
45
|
-
onChange={
|
45
|
+
onChange={(event) => {
|
46
|
+
setFieldValue(event.target.value);
|
47
|
+
}}
|
46
48
|
onBlur={onBlur}
|
47
49
|
name={field.id}
|
48
50
|
value={value}
|
@@ -161,17 +161,11 @@ describe('Text field input', () => {
|
|
161
161
|
it('should record new obs', async () => {
|
162
162
|
await renderForm(textValues);
|
163
163
|
const inputField = screen.getByLabelText('Indicate your notes');
|
164
|
-
|
165
|
-
await user.
|
164
|
+
await user.click(inputField);
|
165
|
+
await user.paste('Updated patient notes');
|
166
166
|
|
167
167
|
await act(async () => {
|
168
|
-
expect(mockSetFieldValue).toHaveBeenCalledWith(
|
169
|
-
expect.objectContaining({
|
170
|
-
target: expect.objectContaining({
|
171
|
-
value: 'Updated patient notes',
|
172
|
-
}),
|
173
|
-
}),
|
174
|
-
);
|
168
|
+
expect(mockSetFieldValue).toHaveBeenCalledWith('Updated patient notes');
|
175
169
|
});
|
176
170
|
});
|
177
171
|
|
@@ -6,7 +6,6 @@ import { formStateReducer, initialState } from './state';
|
|
6
6
|
import { useEvaluateFormFieldExpressions } from '../../../hooks/useEvaluateFormFieldExpressions';
|
7
7
|
import { useFormFactory } from '../../../provider/form-factory-provider';
|
8
8
|
import { FormProvider, type FormContextProps } from '../../../provider/form-provider';
|
9
|
-
import { isTrue } from '../../../utils/boolean-utils';
|
10
9
|
import { type FormProcessorContextProps } from '../../../types';
|
11
10
|
import { useFormStateHelpers } from '../../../hooks/useFormStateHelpers';
|
12
11
|
import { pageObserver } from '../../sidebar/page-observer';
|
@@ -15,6 +15,7 @@ export function cloneRepeatField(srcField: FormField, value: OpenmrsResource, id
|
|
15
15
|
childField.id = `${childField.id}_${idSuffix}`;
|
16
16
|
childField.meta.groupId = clonedField.id;
|
17
17
|
childField.meta.previousValue = null;
|
18
|
+
childField.fieldDependents = new Set();
|
18
19
|
clearSubmission(childField);
|
19
20
|
|
20
21
|
// cleanup expressions
|
@@ -47,12 +47,13 @@ const Repeat: React.FC<FormFieldInputProps> = ({ field }) => {
|
|
47
47
|
|
48
48
|
const handleAdd = useCallback(
|
49
49
|
(counter: number) => {
|
50
|
+
const clonedFieldsBuffer: FormField[] = [];
|
50
51
|
function evaluateExpressions(field: FormField) {
|
51
52
|
if (field.hide?.hideWhenExpression) {
|
52
53
|
field.isHidden = evaluateExpression(
|
53
54
|
field.hide.hideWhenExpression,
|
54
55
|
{ value: field, type: 'field' },
|
55
|
-
formFields,
|
56
|
+
[...formFields, ...clonedFieldsBuffer],
|
56
57
|
getValues(),
|
57
58
|
{
|
58
59
|
mode: sessionMode,
|
@@ -64,7 +65,7 @@ const Repeat: React.FC<FormFieldInputProps> = ({ field }) => {
|
|
64
65
|
evaluateAsyncExpression(
|
65
66
|
field.questionOptions.calculate?.calculateExpression,
|
66
67
|
{ value: field, type: 'field' },
|
67
|
-
formFields,
|
68
|
+
[...formFields, ...clonedFieldsBuffer],
|
68
69
|
getValues(),
|
69
70
|
{
|
70
71
|
mode: sessionMode,
|
@@ -80,16 +81,19 @@ const Repeat: React.FC<FormFieldInputProps> = ({ field }) => {
|
|
80
81
|
}
|
81
82
|
|
82
83
|
const clonedField = cloneRepeatField(field, null, counter);
|
83
|
-
|
84
|
+
clonedFieldsBuffer.push(clonedField);
|
85
|
+
|
86
|
+
// Handle nested questions
|
84
87
|
if (clonedField.type === 'obsGroup') {
|
85
88
|
clonedField.questions?.forEach((childField) => {
|
86
|
-
|
87
|
-
addFormField(childField);
|
89
|
+
clonedFieldsBuffer.push(childField);
|
88
90
|
});
|
89
|
-
} else {
|
90
|
-
evaluateExpressions(clonedField);
|
91
91
|
}
|
92
|
-
|
92
|
+
|
93
|
+
clonedFieldsBuffer.forEach((field) => {
|
94
|
+
evaluateExpressions(field);
|
95
|
+
addFormField(field);
|
96
|
+
});
|
93
97
|
setRows([...rows, clonedField]);
|
94
98
|
},
|
95
99
|
[formFields, field, rows, context],
|
@@ -8,9 +8,24 @@ export function useFormStateHelpers(dispatch: Dispatch<Action>, formFields: Form
|
|
8
8
|
const addFormField = useCallback((field: FormField) => {
|
9
9
|
dispatch({ type: 'ADD_FORM_FIELD', value: field });
|
10
10
|
}, []);
|
11
|
-
const updateFormField = useCallback(
|
12
|
-
|
13
|
-
|
11
|
+
const updateFormField = useCallback(
|
12
|
+
(field: FormField) => {
|
13
|
+
if (field.meta.groupId) {
|
14
|
+
const group = formFields.find((f) => f.id === field.meta.groupId);
|
15
|
+
if (group) {
|
16
|
+
group.questions = group.questions.map((child) => {
|
17
|
+
if (child.id === field.id) {
|
18
|
+
return field;
|
19
|
+
}
|
20
|
+
return child;
|
21
|
+
});
|
22
|
+
updateFormField(group);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
dispatch({ type: 'UPDATE_FORM_FIELD', value: cloneDeep(field) });
|
26
|
+
},
|
27
|
+
[formFields],
|
28
|
+
);
|
14
29
|
|
15
30
|
const getFormField = useCallback(
|
16
31
|
(fieldId: string) => {
|