From e9078dde61ff072c6c3be53d7c0b09d7d735b2d7 Mon Sep 17 00:00:00 2001 From: Jaimos Skriletz Date: Sun, 24 Sep 2023 21:02:05 -0600 Subject: [PATCH 1/2] Fix issue with hidden input probstatusX in gateway quizzes. The number `X` in the hidden input `probstatusX` needs to be the problem ID, but was being set to the index + 1 of the array used to randomized the problems. This causes the single problem grader javascript to hit an error if a test's problems do not start at 1 and are not in sequential order, as mentioned in #2215. Also, since GatewayQuiz.pm assumes the X is the problem ID, and uses this hidden input to get the status of its problems when moving though different pages, a quiz whose problems don't start with 1 or are not in sequential error could retrieve an incorrect status as a result. This update fixes the issue by setting X equal to the problemID. --- templates/ContentGenerator/GatewayQuiz.html.ep | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/ContentGenerator/GatewayQuiz.html.ep b/templates/ContentGenerator/GatewayQuiz.html.ep index 4b35ff4100..f85113404c 100644 --- a/templates/ContentGenerator/GatewayQuiz.html.ep +++ b/templates/ContentGenerator/GatewayQuiz.html.ep @@ -589,7 +589,8 @@ % } % # Store the problem status for continued attempts recording. - <%= hidden_field 'probstatus' . ($probOrder->[$i] + 1) => $c->{probStatus}[ $probOrder->[$i] ] =%> + <%= hidden_field 'probstatus' . $problems->[ $probOrder->[$i] ]{problem_id} + => $c->{probStatus}[ $probOrder->[$i] ] =%> %
% } else { @@ -605,7 +606,8 @@ % } % } % # Store the problem status for continued attempts recording. - <%= hidden_field 'probstatus' . ($probOrder->[$i] + 1) => $c->{probStatus}[ $probOrder->[$i] ] %> + <%= hidden_field 'probstatus' . $problems->[ $probOrder->[$i] ]{problem_id} + => $c->{probStatus}[ $probOrder->[$i] ] %> % } % } % From 3ba523e25665152b7ea289186bba6b6c371aa8db Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Mon, 2 Oct 2023 07:19:25 -0500 Subject: [PATCH 2/2] Validate hidden input existence when saving value in problemgrader.js. This is the real problem that prevents the functionality of the problem grader and causes issue #2215. These hidden inputs not existing for some problems in a test with non-consecutive problems causes a javascript error that prevents the comment from being saved. If the javascript error does not occur then the comment will be saved correctly. To test this create a test with problems 1, 2, 3, and 4, and delete problem 2 (for example). Then submit a version of the test, and open the problem grader in that version. Then go to problem 2 and set the score and add a comment for that problem. With the develop branch you will get the message Error saving score. document.gwquiz.elements[("probstatus" + s.dataset.problemId)] is undefined If you check the database, you will see that the score is saved, but the comment is not. With this branch the score and comment will be successfully saved (and you can verify this in the database). There is still an issue with indexing of the `probstatus` fields in that needs to be resolved. See my comment in #2216 which gives an indication of what is involved. I am still investigating what needs to be done to fix this. --- htdocs/js/ProblemGrader/problemgrader.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/js/ProblemGrader/problemgrader.js b/htdocs/js/ProblemGrader/problemgrader.js index fb86daa368..c1cd644e4e 100644 --- a/htdocs/js/ProblemGrader/problemgrader.js +++ b/htdocs/js/ProblemGrader/problemgrader.js @@ -120,15 +120,16 @@ } else { // Update the hidden problem status fields and score table for gateway quizzes if (saveData.versionId !== '0') { - document.gwquiz.elements['probstatus' + saveData.problemId].value = - parseInt(scoreInput.value) / 100; + const probStatus = document.gwquiz.elements[`probstatus${saveData.problemId}`]; + if (probStatus) probStatus.value = parseInt(scoreInput.value) / 100; let testValue = 0; for (const scoreCell of document.querySelectorAll('table.gwNavigation td.score')) { if (scoreCell.dataset.problemId == saveData.problemId) { scoreCell.textContent = scoreInput.value == '100' ? '\u{1F4AF}' : scoreInput.value; } - testValue += document.gwquiz.elements['probstatus' - + scoreCell.dataset.problemId].value * scoreCell.dataset.problemValue; + testValue += + (document.gwquiz.elements[`probstatus${scoreCell.dataset.problemId}`]?.value ?? 0) * + scoreCell.dataset.problemValue; } const recordedScore = document.getElementById('test-recorded-score'); if (recordedScore) {