@openmrs/esm-form-engine-lib 2.1.0-pre.1409 → 2.1.0-pre.1412
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
@@ -16,11 +16,10 @@ import { hasRendering } from '../../../utils/common-utils';
|
|
16
16
|
import { useFormProviderContext } from '../../../provider/form-provider';
|
17
17
|
import { isEmpty } from '../../../validators/form-validator';
|
18
18
|
import PreviousValueReview from '../../previous-value-review/previous-value-review.component';
|
19
|
-
import { getRegisteredControl } from '../../../registry/registry';
|
19
|
+
import { getFieldControlWithFallback, getRegisteredControl } from '../../../registry/registry';
|
20
20
|
import styles from './form-field-renderer.scss';
|
21
21
|
import { isTrue } from '../../../utils/boolean-utils';
|
22
22
|
import UnspecifiedField from '../../inputs/unspecified/unspecified.component';
|
23
|
-
import { getFieldControlWithFallback } from '../../../utils/form-helper';
|
24
23
|
import { handleFieldLogic } from './fieldLogic';
|
25
24
|
|
26
25
|
export interface FormFieldRendererProps {
|
package/src/registry/registry.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import {
|
2
|
+
type FormField,
|
2
3
|
type DataSource,
|
3
4
|
type FormFieldValidator,
|
4
5
|
type FormSchemaTransformer,
|
@@ -121,7 +122,7 @@ export async function getRegisteredControl(renderType: string) {
|
|
121
122
|
let component = inbuiltControls.find(
|
122
123
|
(control) => control.name === renderType || control?.alias === renderType,
|
123
124
|
)?.component;
|
124
|
-
// if undefined, try
|
125
|
+
// if undefined, try searching through the registered custom controls
|
125
126
|
if (!component) {
|
126
127
|
const importedControl = await getFormsStore()
|
127
128
|
.controls.find((control) => control.name === renderType || control?.alias === renderType)
|
@@ -132,6 +133,26 @@ export async function getRegisteredControl(renderType: string) {
|
|
132
133
|
return component;
|
133
134
|
}
|
134
135
|
|
136
|
+
/**
|
137
|
+
* Retrieves the appropriate field control for a question, considering missing concepts.
|
138
|
+
* If the question is of type 'obs' and has a missing concept, it falls back to a disabled text input.
|
139
|
+
* Otherwise, it retrieves the registered control based on the rendering specified in the question.
|
140
|
+
* @param question - The FormField representing the question.
|
141
|
+
* @returns The field control to be used for rendering the question.
|
142
|
+
*/
|
143
|
+
export function getFieldControlWithFallback(question: FormField) {
|
144
|
+
// Check if the question has a missing concept
|
145
|
+
if (hasMissingConcept(question)) {
|
146
|
+
// If so, render a disabled text input
|
147
|
+
question.disabled = true;
|
148
|
+
question.isDisabled = true;
|
149
|
+
return getRegisteredControl('text');
|
150
|
+
}
|
151
|
+
|
152
|
+
// Retrieve the registered control based on the specified rendering
|
153
|
+
return getRegisteredControl(question.questionOptions.rendering);
|
154
|
+
}
|
155
|
+
|
135
156
|
export async function getRegisteredFieldValueAdapter(type: string): Promise<FormFieldValueAdapter> {
|
136
157
|
if (registryCache.fieldValueAdapters[type]) {
|
137
158
|
return registryCache.fieldValueAdapters[type];
|
@@ -259,3 +280,9 @@ function getFormsStore(): FormsRegistryStoreState {
|
|
259
280
|
formSchemaTransformers: [],
|
260
281
|
}).getState();
|
261
282
|
}
|
283
|
+
|
284
|
+
function hasMissingConcept(question: FormField) {
|
285
|
+
return (
|
286
|
+
question.type == 'obs' && !question.questionOptions.concept && question.questionOptions.rendering !== 'fixed-value'
|
287
|
+
);
|
288
|
+
}
|
package/src/utils/form-helper.ts
CHANGED
@@ -158,32 +158,6 @@ export function findConceptByReference(reference: string, concepts) {
|
|
158
158
|
}
|
159
159
|
}
|
160
160
|
|
161
|
-
/**
|
162
|
-
* Retrieves the appropriate field control for a question, considering missing concepts.
|
163
|
-
* If the question is of type 'obs' and has a missing concept, it falls back to a disabled text input.
|
164
|
-
* Otherwise, it retrieves the registered control based on the rendering specified in the question.
|
165
|
-
* @param question - The FormField representing the question.
|
166
|
-
* @returns The field control to be used for rendering the question.
|
167
|
-
*/
|
168
|
-
export function getFieldControlWithFallback(question: FormField) {
|
169
|
-
// Check if the question has a missing concept
|
170
|
-
if (hasMissingConcept(question)) {
|
171
|
-
// If so, render a disabled text input
|
172
|
-
question.disabled = true;
|
173
|
-
question.isDisabled = true;
|
174
|
-
return getRegisteredControl('text');
|
175
|
-
}
|
176
|
-
|
177
|
-
// Retrieve the registered control based on the specified rendering
|
178
|
-
return getRegisteredControl(question.questionOptions.rendering);
|
179
|
-
}
|
180
|
-
|
181
|
-
export function hasMissingConcept(question: FormField) {
|
182
|
-
return (
|
183
|
-
question.type == 'obs' && !question.questionOptions.concept && question.questionOptions.rendering !== 'fixed-value'
|
184
|
-
);
|
185
|
-
}
|
186
|
-
|
187
161
|
export function scrollIntoView(viewId: string, shouldFocus: boolean = false) {
|
188
162
|
const currentElement = document.getElementById(viewId);
|
189
163
|
currentElement?.scrollIntoView({
|