@openmrs/esm-form-engine-lib 2.1.0-pre.1476 → 2.1.0-pre.1485
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 +1 -1
- package/src/components/inputs/date/date.component.tsx +1 -0
- package/src/components/inputs/multi-select/multi-select.component.tsx +4 -2
- package/src/components/inputs/number/number.component.tsx +1 -1
- package/src/components/inputs/radio/radio.component.tsx +1 -0
- package/src/components/inputs/select/dropdown.component.tsx +1 -1
- package/src/components/inputs/text-area/text-area.component.tsx +1 -1
- package/src/components/inputs/toggle/toggle.component.tsx +1 -1
- package/src/components/inputs/ui-select-extended/ui-select-extended.component.tsx +1 -1
- package/src/components/inputs/workspace-launcher/workspace-launcher.component.tsx +2 -1
- package/src/components/processor-factory/form-processor-factory.component.tsx +1 -0
- package/src/components/renderer/form/form-renderer.component.tsx +10 -9
- package/src/form-engine.component.tsx +0 -1
- package/src/provider/form-factory-provider.tsx +5 -5
- package/75e0dfeda364f646/75e0dfeda364f646.gz +0 -0
- package/b211b244de3a9350/b211b244de3a9350.gz +0 -0
- package/cacdacff9a5c84a8/cacdacff9a5c84a8.gz +0 -0
- package/cbf7151ea0b21ed7/cbf7151ea0b21ed7.gz +0 -0
package/package.json
CHANGED
@@ -118,6 +118,7 @@ const DateField: React.FC<FormFieldInputProps> = ({ field, value: dateValue, err
|
|
118
118
|
disabled={field.datePickerFormat === 'timer' ? field.isDisabled : !dateValue ? true : false}
|
119
119
|
invalid={errors.length > 0}
|
120
120
|
invalidText={errors[0]?.message}
|
121
|
+
readOnly={isTrue(field.readonly)}
|
121
122
|
warning={warnings.length > 0}
|
122
123
|
warningText={warnings[0]?.message}
|
123
124
|
value={
|
@@ -25,6 +25,7 @@ const MultiSelect: React.FC<FormFieldInputProps> = ({ field, value, errors, warn
|
|
25
25
|
label: answer.label,
|
26
26
|
key: index,
|
27
27
|
disabled: answer.disable?.isDisabled,
|
28
|
+
readonly: isTrue(field.readonly),
|
28
29
|
}));
|
29
30
|
|
30
31
|
const initiallySelectedQuestionItems = useMemo(() => {
|
@@ -110,10 +111,10 @@ const MultiSelect: React.FC<FormFieldInputProps> = ({ field, value, errors, warn
|
|
110
111
|
invalidText={errors[0]?.message}
|
111
112
|
warn={warnings.length > 0}
|
112
113
|
warnText={warnings[0]?.message}
|
113
|
-
readOnly={field.readonly}
|
114
|
+
readOnly={isTrue(field.readonly)}
|
114
115
|
/>
|
115
116
|
) : (
|
116
|
-
<CheckboxGroup legendText={label} name={field.id}>
|
117
|
+
<CheckboxGroup legendText={label} name={field.id} readOnly={isTrue(field.readonly)}>
|
117
118
|
{field.questionOptions.answers?.map((value, index) => {
|
118
119
|
return (
|
119
120
|
<Checkbox
|
@@ -129,6 +130,7 @@ const MultiSelect: React.FC<FormFieldInputProps> = ({ field, value, errors, warn
|
|
129
130
|
checked={initiallyCheckedQuestionItems.some((item) => item === value.concept)}
|
130
131
|
onBlur={onblur}
|
131
132
|
disabled={value.disable?.isDisabled}
|
133
|
+
readOnly={isTrue(field.readonly)}
|
132
134
|
/>
|
133
135
|
);
|
134
136
|
})}
|
@@ -65,7 +65,7 @@ const NumberField: React.FC<FormFieldInputProps> = ({ field, value, errors, warn
|
|
65
65
|
hideSteppers={true}
|
66
66
|
onWheel={(e) => e.target.blur()}
|
67
67
|
disabled={field.isDisabled}
|
68
|
-
readOnly={field.readonly}
|
68
|
+
readOnly={isTrue(field.readonly)}
|
69
69
|
className={classNames(styles.controlWidthConstrained, styles.boldedLabel)}
|
70
70
|
warn={warnings.length > 0}
|
71
71
|
warnText={warnings[0]?.message}
|
@@ -42,6 +42,7 @@ const Radio: React.FC<FormFieldInputProps> = ({ field, value, errors, warnings,
|
|
42
42
|
name={field.id}
|
43
43
|
valueSelected={value}
|
44
44
|
onChange={handleChange}
|
45
|
+
readOnly={isTrue(field.readonly)}
|
45
46
|
orientation={field.questionOptions?.orientation || 'vertical'}>
|
46
47
|
{field.questionOptions.answers
|
47
48
|
.filter((answer) => !answer.isHidden)
|
@@ -69,7 +69,7 @@ const Dropdown: React.FC<FormFieldInputProps> = ({ field, value, errors, warning
|
|
69
69
|
selectedItem={isEmpty(value) ? NullSelectOption : value}
|
70
70
|
onChange={handleChange}
|
71
71
|
disabled={field.isDisabled}
|
72
|
-
readOnly={field.readonly}
|
72
|
+
readOnly={isTrue(field.readonly)}
|
73
73
|
invalid={errors.length > 0}
|
74
74
|
invalidText={errors[0]?.message}
|
75
75
|
warn={warnings.length > 0}
|
@@ -48,7 +48,7 @@ const TextArea: React.FC<FormFieldInputProps> = ({ field, value, errors, warning
|
|
48
48
|
value={value || ''}
|
49
49
|
rows={field.questionOptions.rows || 4}
|
50
50
|
disabled={field.isDisabled}
|
51
|
-
readOnly={field.readonly}
|
51
|
+
readOnly={isTrue(field.readonly)}
|
52
52
|
invalid={errors.length > 0}
|
53
53
|
invalidText={errors[0]?.message}
|
54
54
|
warn={warnings.length > 0}
|
@@ -154,7 +154,7 @@ const UiSelectExtended: React.FC<FormFieldInputProps> = ({ field, errors, warnin
|
|
154
154
|
setFieldValue(selectedItem?.uuid);
|
155
155
|
}}
|
156
156
|
disabled={field.isDisabled}
|
157
|
-
readOnly={field.readonly}
|
157
|
+
readOnly={isTrue(field.readonly)}
|
158
158
|
invalid={errors.length > 0}
|
159
159
|
invalidText={errors.length && errors[0].message}
|
160
160
|
onInputChange={(value) => {
|
@@ -4,6 +4,7 @@ import { showSnackbar } from '@openmrs/esm-framework';
|
|
4
4
|
import { useLaunchWorkspaceRequiringVisit } from '@openmrs/esm-patient-common-lib';
|
5
5
|
import { Button } from '@carbon/react';
|
6
6
|
import { type FormFieldInputProps } from '../../../types';
|
7
|
+
import { isTrue } from '../../../utils/boolean-utils';
|
7
8
|
import styles from './workspace-launcher.scss';
|
8
9
|
|
9
10
|
const WorkspaceLauncher: React.FC<FormFieldInputProps> = ({ field }) => {
|
@@ -27,7 +28,7 @@ const WorkspaceLauncher: React.FC<FormFieldInputProps> = ({ field }) => {
|
|
27
28
|
<div>
|
28
29
|
<div className={styles.label}>{t(field.label)}</div>
|
29
30
|
<div className={styles.workspaceButton}>
|
30
|
-
<Button onClick={handleLaunchWorkspace}>{field.questionOptions?.buttonLabel ?? t('launchWorkspace')}</Button>
|
31
|
+
<Button disabled={isTrue(field.readonly)} onClick={handleLaunchWorkspace}>{field.questionOptions?.buttonLabel ?? t('launchWorkspace')}</Button>
|
31
32
|
</div>
|
32
33
|
</div>
|
33
34
|
)
|
@@ -13,10 +13,16 @@ import { useFormStateHelpers } from '../../../hooks/useFormStateHelpers';
|
|
13
13
|
export type FormRendererProps = {
|
14
14
|
processorContext: FormProcessorContextProps;
|
15
15
|
initialValues: Record<string, any>;
|
16
|
+
isSubForm: boolean;
|
16
17
|
setIsLoadingFormDependencies: (isLoading: boolean) => void;
|
17
18
|
};
|
18
19
|
|
19
|
-
export const FormRenderer = ({
|
20
|
+
export const FormRenderer = ({
|
21
|
+
processorContext,
|
22
|
+
initialValues,
|
23
|
+
isSubForm,
|
24
|
+
setIsLoadingFormDependencies,
|
25
|
+
}: FormRendererProps) => {
|
20
26
|
const { evaluatedFields, evaluatedFormJson } = useEvaluateFormFieldExpressions(initialValues, processorContext);
|
21
27
|
const { registerForm, setIsFormDirty, workspaceLayout } = useFormFactory();
|
22
28
|
const methods = useForm({
|
@@ -64,8 +70,8 @@ export const FormRenderer = ({ processorContext, initialValues, setIsLoadingForm
|
|
64
70
|
}, [processorContext, workspaceLayout, methods, formFields, formJson, invalidFields]);
|
65
71
|
|
66
72
|
useEffect(() => {
|
67
|
-
registerForm(formJson.name, context);
|
68
|
-
}, [formJson.name, context]);
|
73
|
+
registerForm(formJson.name, isSubForm, context);
|
74
|
+
}, [formJson.name, isSubForm, context]);
|
69
75
|
|
70
76
|
useEffect(() => {
|
71
77
|
setIsFormDirty(isDirty);
|
@@ -91,12 +97,7 @@ export const FormRenderer = ({ processorContext, initialValues, setIsLoadingForm
|
|
91
97
|
/>
|
92
98
|
);
|
93
99
|
}
|
94
|
-
return
|
95
|
-
<PageRenderer
|
96
|
-
key={page.label}
|
97
|
-
page={page}
|
98
|
-
/>
|
99
|
-
);
|
100
|
+
return <PageRenderer key={page.label} page={page} />;
|
100
101
|
})}
|
101
102
|
</FormProvider>
|
102
103
|
);
|
@@ -26,7 +26,7 @@ interface FormFactoryProviderContextProps {
|
|
26
26
|
visit: OpenmrsResource;
|
27
27
|
location: OpenmrsResource;
|
28
28
|
provider: OpenmrsResource;
|
29
|
-
registerForm: (formId: string, context: FormContextProps) => void;
|
29
|
+
registerForm: (formId: string, isSubForm: boolean, context: FormContextProps) => void;
|
30
30
|
setCurrentPage: (page: string) => void;
|
31
31
|
handleConfirmQuestionDeletion?: (question: Readonly<FormField>) => Promise<void>;
|
32
32
|
setIsFormDirty: (isFormDirty: boolean) => void;
|
@@ -80,11 +80,11 @@ export const FormFactoryProvider: React.FC<FormFactoryProviderProps> = ({
|
|
80
80
|
|
81
81
|
const abortController = new AbortController();
|
82
82
|
|
83
|
-
const registerForm = useCallback((formId: string, context: FormContextProps) => {
|
84
|
-
if (
|
85
|
-
rootForm.current = context;
|
86
|
-
} else if (rootForm.current.formJson.name !== formId) {
|
83
|
+
const registerForm = useCallback((formId: string, isSubForm: boolean, context: FormContextProps) => {
|
84
|
+
if (isSubForm) {
|
87
85
|
subForms.current[formId] = context;
|
86
|
+
} else {
|
87
|
+
rootForm.current = context;
|
88
88
|
}
|
89
89
|
}, []);
|
90
90
|
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|