Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
evilaliv3 committed Nov 26, 2024
1 parent 4e9ff08 commit 2ed9e5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ export class SubmissionComponent implements OnInit {
});
}

const required_status = this.fieldUtilitiesService.onAnswersUpdate(this);
this.fieldUtilitiesService.onAnswersUpdate(this);

if (!this.runValidation() || required_status) {
if (!this.runValidation()) {
this.utilsService.scrollToTop();
return;
}
Expand Down
23 changes: 7 additions & 16 deletions client/app/src/shared/services/field-utilities.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ export class FieldUtilitiesService {
}
}

updateAnswers(scope: any, parent: any, list: any, answers: any): boolean {
let ret=false, entry, option, i, j;
updateAnswers(scope: any, parent: any, list: any, answers: any) {
let entry, option, i, j;

list.forEach((field: any) => {
if (this.isFieldTriggered(parent, field, scope.answers, scope.score)) {
Expand All @@ -164,10 +164,10 @@ export class FieldUtilitiesService {

if (field.id in answers) {
for (i = 0; i < answers[field.id].length; i++) {
ret = ret || this.updateAnswers(scope, field, field.children, answers[field.id][i]);
this.updateAnswers(scope, field, field.children, answers[field.id][i]);
}
} else {
ret = ret || this.updateAnswers(scope, field, field.children, {});
this.updateAnswers(scope, field, field.children, {});
}

if (!field.enabled) {
Expand Down Expand Up @@ -205,8 +205,6 @@ export class FieldUtilitiesService {
entry.required_status = field.required && !entry["value"];
}

ret = ret || entry.required_status;

if (["checkbox", "selectbox", "multichoice"].indexOf(field.type) > -1) {
for (j = 0; j < field.options.length; j++) {
option = field.options[j];
Expand Down Expand Up @@ -234,38 +232,31 @@ export class FieldUtilitiesService {
}
}
});

return ret;
}

onAnswersUpdate(scope: any): boolean {
onAnswersUpdate(scope: any) {
scope.block_submission = false;
scope.score = 0;
scope.points_to_sum = 0;
scope.points_to_mul = 1;

if (!scope.questionnaire) {
return true;
return;
}

if (scope.submissionService) {
scope.submissionService.override_receivers = [];
}

let ret = false, recursive_ret = false;

scope.questionnaire.steps.forEach((step: any) => {
step.enabled = this.isFieldTriggered(null, step, scope.answers, scope.score);
recursive_ret = this.updateAnswers(scope, step, step.children, scope.answers);
ret = ret || recursive_ret;
this.updateAnswers(scope, step, step.children, scope.answers);
});

if (scope.context) {
scope.submissionService.submission.score = scope.score;
scope.submissionService.blocked = scope.block_submission;
}

return ret;
}


Expand Down

0 comments on commit 2ed9e5d

Please sign in to comment.