Fix problem_data with problem randomization and show me another. #2855
+21
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theproblemDatatranslation 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:
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 => 0option 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.