Skip to content

Commit 2d2d82f

Browse files
committed
Tweak sticky answers with problem randomization a bit more.
Previously if a new problem version is being opened, then the answers from a previous version were deleted from the form fields of the last form submission. Now, the form fields form any previous form submission are simply not even sent to PG. If this is a new problem version, there is absolutely nothing in the form fields that PG needs. This is a much more efficient and thorough approach. It ensures that if a problem uses some other inputs that are not part of the answer, those inputs are cleared as well. GeoGebra problems do this for instance to save their state.
1 parent f944306 commit 2d2d82f

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

lib/WeBWorK/ContentGenerator/Problem.pm

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -531,18 +531,16 @@ async sub pre_header_initialize ($c) {
531531
# requiring another answer submission.
532532
my $showReturningFeedback = 0;
533533

534-
# Sticky answers
535-
if (!($c->{submitAnswers} || $previewAnswers || $checkAnswers) && $will{showOldAnswers}) {
534+
# Reinsert sticky answers. Do this only if new answers are NOT being submitted,
535+
# and a new problem version is NOT being opened.
536+
if (!($prEnabled && !$problem->{prCount})
537+
&& !($c->{submitAnswers} || $previewAnswers || $checkAnswers)
538+
&& $will{showOldAnswers})
539+
{
536540
my %oldAnswers = decodeAnswers($problem->last_answer);
537-
# Do this only if new answers are NOT being submitted
538-
if ($prEnabled && !$problem->{prCount}) {
539-
# Clear answers if this is a new problem version
540-
delete $formFields->{$_} for keys %oldAnswers;
541-
} else {
542-
$formFields->{$_} = $oldAnswers{$_} for (keys %oldAnswers);
543-
$showReturningFeedback = 1
544-
if $ce->{pg}{options}{automaticAnswerFeedback} && $problem->num_correct + $problem->num_incorrect > 0;
545-
}
541+
$formFields->{$_} = $oldAnswers{$_} for (keys %oldAnswers);
542+
$showReturningFeedback = 1
543+
if $ce->{pg}{options}{automaticAnswerFeedback} && $problem->num_correct + $problem->num_incorrect > 0;
546544
}
547545

548546
my $showOnlyCorrectAnswers = $c->param('showCorrectAnswers') && $will{showCorrectAnswers};
@@ -555,7 +553,9 @@ async sub pre_header_initialize ($c) {
555553
$c->{set},
556554
$problem,
557555
$c->{set}->psvn,
558-
$formFields,
556+
$prEnabled
557+
&& !$problem->{prCount}
558+
&& !($c->{submitAnswers} || $previewAnswers || $checkAnswers) ? {} : $formFields,
559559
{
560560
displayMode => $displayMode,
561561
showHints => $will{showHints},

0 commit comments

Comments
 (0)