Skip to content

Commit

Permalink
Validate hidden input existence when saving value in problemgrader.js.
Browse files Browse the repository at this point in the history
This is the real problem that prevents the functionality of the problem
grader and causes issue openwebwork#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 openwebwork#2216 which gives an
indication of what is involved.  I am still investigating what needs to
be done to fix this.
  • Loading branch information
drgrice1 authored and somiaj committed Oct 22, 2023
1 parent e9078dd commit 3ba523e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions htdocs/js/ProblemGrader/problemgrader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3ba523e

Please sign in to comment.