Skip to content

Commit

Permalink
fix: reset sub fields on no selection
Browse files Browse the repository at this point in the history
  • Loading branch information
9sneha-n committed Aug 2, 2024
1 parent 398aee9 commit f83f3d2
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/domain/entities/Questionnaire/QuestionnaireQuestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,29 @@ export class QuestionnaireQuestion {

return parsedAndUpdatedQuestion;
});
//If any of the updated question has been changed to hidden, then reset its value
//When it is shown again, the user can enter a "fresh" value
const hiddenQuestions = parsedAndUpdatedQuestions.filter(
q =>
q.isVisible === false &&
updatedQuestions.find(uq => uq.id === q.id)?.isVisible === true
);

return _(parsedAndUpdatedQuestions)
if (hiddenQuestions.length === 0)
return _(parsedAndUpdatedQuestions)
.sortBy(question => question.sortOrder)
.value();

const resetQuestions = hiddenQuestions.reduce((acc, hiddenQuestion) => {
return this.updateQuestions(
acc,
{ ...hiddenQuestion, value: undefined },
rules,
questionnaire
);
}, parsedAndUpdatedQuestions);

return _(resetQuestions)
.sortBy(question => question.sortOrder)
.value();
}
Expand Down

0 comments on commit f83f3d2

Please sign in to comment.