From 464af344e7633d62cfe8f383af27008c1f7a1b69 Mon Sep 17 00:00:00 2001 From: rinrub <99617143+rinrub@users.noreply.github.com> Date: Mon, 19 Feb 2024 10:41:24 +0100 Subject: [PATCH 1/2] add initial value to repeatable boolean --- src/reducers/form.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/reducers/form.ts b/src/reducers/form.ts index 4161116d..176f7727 100644 --- a/src/reducers/form.ts +++ b/src/reducers/form.ts @@ -155,7 +155,13 @@ function processAddRepeatItemAction(action: NewValueAction, state: Form): Form { if (!newItem) { return; } - + if (item?.type === ItemType.BOOLEAN) { + if (item.initial && item.initial.length > 0 && item.initial[0].valueBoolean !== undefined) { + newItem.answer = [{ valueBoolean: item.initial[0]?.valueBoolean }]; + } else { + newItem.answer = [{ valueBoolean: false }]; + } + } const indexToInsert = arrayToAddItemTo.map(o => o.linkId).lastIndexOf(newItem.linkId); arrayToAddItemTo.splice(indexToInsert + 1, 0, newItem); }); From fc04c65ea5ef45ce25e8106975f55ba3cc8951b2 Mon Sep 17 00:00:00 2001 From: rinrub <99617143+rinrub@users.noreply.github.com> Date: Mon, 19 Feb 2024 10:56:15 +0100 Subject: [PATCH 2/2] added v and changelog --- CHANGES | 6 ++++++ package.json | 2 +- src/reducers/form.ts | 16 +++++++++------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 72cb8221..c933e6ae 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +## 14.0.8 + +--- + +- Bugfix: When Confirmation is repeatable, the added items now have a initial value of false + ## 14.0.7 --- diff --git a/package.json b/package.json index ab761cc6..9b92646c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@helsenorge/refero", - "version": "14.0.7", + "version": "14.0.8", "engines": { "node": "^18.0.0", "npm": ">=9.0.0" diff --git a/src/reducers/form.ts b/src/reducers/form.ts index 176f7727..22d23943 100644 --- a/src/reducers/form.ts +++ b/src/reducers/form.ts @@ -27,6 +27,7 @@ import { REMOVE_ATTACHMENT_VALUE, } from '../actions/newValue'; import { syncQuestionnaireResponse } from '../actions/syncQuestionnaireResponse'; +import itemType from '../constants/itemType'; import { GlobalState } from '../reducers/index'; import { createQuestionnaireResponseAnswer } from '../util/createQuestionnaireResponseAnswer'; import { getMinOccursExtensionValue } from '../util/extension'; @@ -124,17 +125,18 @@ function getArrayToAddGroupTo(itemToAddTo: QuestionnaireResponseItem | undefined } function processAddRepeatItemAction(action: NewValueAction, state: Form): Form { + const { parentPath, responseItems, item } = action; return produce(state, draft => { - if (!action.parentPath) { + if (!parentPath) { return state; } let arrayToAddItemTo: Array | undefined = []; - if (action.parentPath.length === 0 && draft.FormData.Content) { + if (parentPath.length === 0 && draft.FormData.Content) { arrayToAddItemTo = draft.FormData.Content.item; - } else if (action.parentPath.length > 0) { + } else if (parentPath.length > 0) { // length >1 means group wrapped in group - const itemToAddTo = getResponseItemWithPath(action.parentPath, draft.FormData); + const itemToAddTo = getResponseItemWithPath(parentPath, draft.FormData); arrayToAddItemTo = getArrayToAddGroupTo(itemToAddTo); } @@ -142,12 +144,12 @@ function processAddRepeatItemAction(action: NewValueAction, state: Form): Form { return; } - if (!action.responseItems || action.responseItems.length === 0) { + if (!responseItems || responseItems.length === 0) { return; } const newItem = copyItem( - action.responseItems[0], + responseItems[0], undefined, draft.FormDefinition.Content as Questionnaire, state.FormDefinition.Content as Questionnaire @@ -155,7 +157,7 @@ function processAddRepeatItemAction(action: NewValueAction, state: Form): Form { if (!newItem) { return; } - if (item?.type === ItemType.BOOLEAN) { + if (item?.type === itemType.BOOLEAN) { if (item.initial && item.initial.length > 0 && item.initial[0].valueBoolean !== undefined) { newItem.answer = [{ valueBoolean: item.initial[0]?.valueBoolean }]; } else {