Skip to content

Commit

Permalink
OHRI-1983: handled the (Uncaught TypeError: t.forEach is not a functi… (
Browse files Browse the repository at this point in the history
#148)

* OHRI-1983: handled the (Uncaught TypeError: t.forEach is not a function) pop up error

* update to check wether values is an array
  • Loading branch information
Herobiam authored Nov 21, 2023
1 parent c36156b commit 832ef9d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/submission-handlers/base-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,25 @@ const multiSelectObsHandler = (field: OHRIFormField, values: Array<string>, cont
if (!field.value) {
field.value = [];
}
values.forEach((value) => {
const obs = field.value.find((o) => {
if (typeof o.value == 'string') {
return o.value == value;
if (Array.isArray(values)) {
values.forEach((value) => {
const obs = field.value.find((o) => {
if (typeof o.value == 'string') {
return o.value == value;
}
return o.value.uuid == value;
});
if (obs && obs.voided) {
obs.voided = false;
} else {
obs || field.value.push(constructObs(value, context, field));
}
return o.value.uuid == value;
});
if (obs && obs.voided) {
obs.voided = false;
} else {
obs || field.value.push(constructObs(value, context, field));
}
});
}

// void or remove unchecked options
field.questionOptions.answers
.filter((opt) => !values.some((v) => v == opt.concept))
.filter((opt) => Array.isArray(values) && !values?.some((v) => v == opt.concept))
.forEach((opt) => {
const observations = field.value.filter((o) => {
if (typeof o.value == 'string') {
Expand Down

0 comments on commit 832ef9d

Please sign in to comment.