Skip to content

Conversation

@drgrice1
Copy link
Member

@drgrice1 drgrice1 commented Dec 5, 2025

When problem randomization is enabled and a new problem version is opened, don't use the problem data from the previous version.

When show me another is enabled don't use the problem data from the assigned problem.

To fix these issues force an empty problem data hash by passing '{}' as the problemData translation option and forces the usage of the hidden problem_data input for show me another problems.

The following example can be used to test this:

DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'scaffold.pl');

$a = random(1,  10);
$b = random(11, 20);

Scaffold::Begin(
    is_open                  => 'correct_or_first_incorrect',
    preview_can_change_state => 0
);

Section::Begin('Part 1');
BEGIN_PGML
Enter [`[$a]`]: [_]{$a}{5}
END_PGML
Section::End();

Section::Begin('Part 2');
BEGIN_PGML
Enter [`[$b]`] [_]{$b}{5}
END_PGML
Section::End();

Scaffold::End();

ENDDOCUMENT();

Add that problem to a set and enable both problem randomization and show me another. Then test the following with the develop branch.

Now login as a student user, open the problem in the set, and submit the correct answer for the first part in the problem. Then submit answers enough times to need to request a new version, and then request a new version. Now in the new version, enter an answer and click "Preview My Answers", and the second part will open. Since the scaffold has the preview_can_change_state => 0 option set, even if the "correct" answer is entered the second part should not open when "Preview My Answers" is clicked, but it does (and does so even an incorrect answer is entered).

Now try the "Show Me Another" button after submitting the correct answer to the first part in the assigned problem in the set. In the show me another problem, enter an answer to the first part, and click "Preview My Answers". Again, the second part opens regardless of if the first part is correct or not, and again it shouldn't open even if the first part is correct.

Now test with this pull request, and of course the correct behaviour happens. That is the second part only opens when the first part is submitted (either with "Submit Answers" in the actual set or with "Check Answers" in the show me another problem) and the first part is correct.

EDIT:
This now goes a bit further, and tweaks sticky answers with problem randomization.

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.

When problem randomization is enabled and a new problem version is
opened, don't use the problem data from the previous version.

When show me another is enabled don't use the problem data from the
assigned problem.

To fix these issues force an empty problem data hash by passing `'{}'`
as the `problemData` translation option and forces the usage of the
hidden problem_data input for show me another problems.

The following example can be used to test this:

```perl
DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'scaffold.pl');

$a = random(1,  10);
$b = random(11, 20);

Scaffold::Begin(
    is_open                  => 'correct_or_first_incorrect',
    preview_can_change_state => 0
);

Section::Begin('Part 1');
BEGIN_PGML
Enter [`[$a]`]: [_]{$a}{5}
END_PGML
Section::End();

Section::Begin('Part 2');
BEGIN_PGML
Enter [`[$b]`] [_]{$b}{5}
END_PGML
Section::End();

Scaffold::End();

ENDDOCUMENT();
```

Add that problem to a set and enable both problem randomization and show
me another.  Then test the following with the develop branch.

Now login as a student user, open the problem in the set, and submit the
correct answer for the first part in the problem.  Then submit answers
enough times to need to request a new version, and then request a new
version.  Now in the new version, enter an answer and click "Preview My
Answers", and the second part will open. Since the scaffold has the
`preview_can_change_state => 0` option set, even if the "correct" answer
is entered the second part should not open when "Preview My Answers" is
clicked, but it does (and does so even an incorrect answer is entered).

Now try the "Show Me Another" button after submitting the correct answer
to the first part in the assigned problem in the set.  In the show me
another problem, enter an answer to the first part, and click "Preview
My Answers".  Again, the second part opens regardless of if the first
part is correct or not, and again it shouldn't open even if the first
part is correct.

Now test with this pull request, and of course the correct behaviour
happens.  That is the second part only opens when the first part is
submitted (either with "Submit Answers" in the actual set or with "Check
Answers" in the show me another problem) and the first part is correct.
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.
@drgrice1 drgrice1 force-pushed the bugfix/problem-data-issues branch from 1159c10 to 0a004d7 Compare December 5, 2025 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant