From a0a9002780928fbdf3783d51bdbcd3e97f5b3321 Mon Sep 17 00:00:00 2001 From: himeshr Date: Fri, 3 May 2024 18:01:18 +0530 Subject: [PATCH] 1133 | Allow adding questionGroup only if none of the existing ones are empty --- src/dataEntryApp/components/QuestionGroupFormElement.js | 2 +- .../components/RepeatableQuestionGroupElement.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/dataEntryApp/components/QuestionGroupFormElement.js b/src/dataEntryApp/components/QuestionGroupFormElement.js index 9ff35d172..45107551b 100644 --- a/src/dataEntryApp/components/QuestionGroupFormElement.js +++ b/src/dataEntryApp/components/QuestionGroupFormElement.js @@ -72,7 +72,7 @@ export default function QuestionGroupFormElement({ concept={childFormElement.concept} obsHolder={obsHolder} value={value} - validationResults={validationResults.filter(itr => itr.questionGroupIndex === questionGroupIndex)} + validationResults={validationResults} uuid={childFormElement.uuid} update={newValue => { updateObs(formElement, newValue, childFormElement, questionGroupIndex); diff --git a/src/dataEntryApp/components/RepeatableQuestionGroupElement.js b/src/dataEntryApp/components/RepeatableQuestionGroupElement.js index 205f9a54d..32923154d 100644 --- a/src/dataEntryApp/components/RepeatableQuestionGroupElement.js +++ b/src/dataEntryApp/components/RepeatableQuestionGroupElement.js @@ -31,8 +31,11 @@ export function RepeatableQuestionGroupElement({ if (hasNoObservation) repeatableQuestionGroup = new RepeatableQuestionGroup(); const repeatableQuestionGroupValue = repeatableQuestionGroup.getValue(); const hasMultipleElements = repeatableQuestionGroupValue.length > 1; + const oneOfTheQuestionGroupObservationsIsEmpty = _.some(repeatableQuestionGroupValue, x => _.isEmpty(x.groupObservations)); return repeatableQuestionGroupValue.map((x, index) => { - const isLastElement = !hasNoObservation && repeatableQuestionGroupValue.length === index + 1; + const isLastElement = + !hasNoObservation && !oneOfTheQuestionGroupObservationsIsEmpty && repeatableQuestionGroupValue.length === index + 1; + const quesGrpValidationResults = validationResults.filter(itr => itr.questionGroupIndex === index); return (