@openmrs/esm-form-engine-lib 4.1.1-pre.2355 → 4.1.1-pre.2357
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repeat.component.d.ts","sourceRoot":"","sources":["../../../src/components/repeat/repeat.component.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoD,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"repeat.component.d.ts","sourceRoot":"","sources":["../../../src/components/repeat/repeat.component.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoD,MAAM,OAAO,CAAC;AACzE,OAAO,KAAK,EAAa,mBAAmB,EAAc,MAAM,aAAa,CAAC;AAkB9E,QAAA,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAwKzC,CAAC;AAmBF,eAAe,MAAM,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
-
import { useTranslation } from "react-i18next";
|
|
3
2
|
import { evaluateAsyncExpression, evaluateExpression } from "../../utils/expression-runner.js";
|
|
4
3
|
import { isEmpty } from "../../validators/form-validator.js";
|
|
5
4
|
import styles from "./repeat.scss";
|
|
@@ -16,15 +15,11 @@ const renderingByTypeMap = {
|
|
|
16
15
|
diagnosis: 'ui-select-extended'
|
|
17
16
|
};
|
|
18
17
|
const Repeat = ({ field })=>{
|
|
19
|
-
const { t } = useTranslation();
|
|
20
|
-
const isGrouped = useMemo(()=>field.questions?.length > 1, [
|
|
21
|
-
field
|
|
22
|
-
]);
|
|
23
18
|
const [counter, setCounter] = useState(0);
|
|
24
19
|
const [rows, setRows] = useState([]);
|
|
25
20
|
const context = useFormProviderContext();
|
|
26
21
|
const { handleConfirmQuestionDeletion } = useFormFactory();
|
|
27
|
-
const { patient, sessionMode, formFieldAdapters, formFields, methods: { getValues, setValue }, addFormField, removeFormField, deletedFields, setDeletedFields, visit } = context;
|
|
22
|
+
const { patient, sessionMode, formFieldAdapters, formFields, methods: { getValues, setValue, unregister }, addFormField, removeFormField, deletedFields, setDeletedFields, visit } = context;
|
|
28
23
|
useEffect(()=>{
|
|
29
24
|
const repeatedFields = formFields.filter((_field)=>_field.questionOptions.concept === field.questionOptions.concept && _field.id.startsWith(field.id) && !_field.meta?.repeat?.wasDeleted);
|
|
30
25
|
setCounter(repeatedFields.length - 1);
|
|
@@ -108,6 +103,10 @@ const Repeat = ({ field })=>{
|
|
|
108
103
|
}
|
|
109
104
|
} else {
|
|
110
105
|
clearSubmission(field);
|
|
106
|
+
// Unregister from react-hook-form so a re-added row with the same id
|
|
107
|
+
// starts empty instead of rehydrating the deleted row's value.
|
|
108
|
+
unregister(field.id);
|
|
109
|
+
field.questions?.forEach((child)=>unregister(child.id));
|
|
111
110
|
}
|
|
112
111
|
setRows(rows.filter((q)=>q.id !== field.id));
|
|
113
112
|
setDeletedFields([
|
package/package.json
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import { useTranslation } from 'react-i18next';
|
|
3
2
|
import type { FormField, FormFieldInputProps, RenderType } from '../../types';
|
|
4
3
|
import { evaluateAsyncExpression, evaluateExpression } from '../../utils/expression-runner';
|
|
5
4
|
import { isEmpty } from '../../validators/form-validator';
|
|
@@ -19,8 +18,6 @@ const renderingByTypeMap: Record<string, RenderType> = {
|
|
|
19
18
|
};
|
|
20
19
|
|
|
21
20
|
const Repeat: React.FC<FormFieldInputProps> = ({ field }) => {
|
|
22
|
-
const { t } = useTranslation();
|
|
23
|
-
const isGrouped = useMemo(() => field.questions?.length > 1, [field]);
|
|
24
21
|
const [counter, setCounter] = useState(0);
|
|
25
22
|
const [rows, setRows] = useState([]);
|
|
26
23
|
const context = useFormProviderContext();
|
|
@@ -30,7 +27,7 @@ const Repeat: React.FC<FormFieldInputProps> = ({ field }) => {
|
|
|
30
27
|
sessionMode,
|
|
31
28
|
formFieldAdapters,
|
|
32
29
|
formFields,
|
|
33
|
-
methods: { getValues, setValue },
|
|
30
|
+
methods: { getValues, setValue, unregister },
|
|
34
31
|
addFormField,
|
|
35
32
|
removeFormField,
|
|
36
33
|
deletedFields,
|
|
@@ -117,6 +114,10 @@ const Repeat: React.FC<FormFieldInputProps> = ({ field }) => {
|
|
|
117
114
|
}
|
|
118
115
|
} else {
|
|
119
116
|
clearSubmission(field);
|
|
117
|
+
// Unregister from react-hook-form so a re-added row with the same id
|
|
118
|
+
// starts empty instead of rehydrating the deleted row's value.
|
|
119
|
+
unregister(field.id);
|
|
120
|
+
field.questions?.forEach((child) => unregister(child.id));
|
|
120
121
|
}
|
|
121
122
|
setRows(rows.filter((q) => q.id !== field.id));
|
|
122
123
|
setDeletedFields([...deletedFields, field]);
|