The Problem
When we turn on backwards navigation and we have multi-choice questions that support multiple answers the checkbox states don't get preserved.
Steps to reproduce:
Step 1: Create the Quiz
1. Create a new quiz
2. Click the “Backwards” navigation checkbox
3. Add three questions each with their own answers.
4. For your questions give them the following settings:
- Question 1: Accept multiple answers
- Question 2: Do not accept multiple answers
- Question 3: Accept multiple answers.
Step 2: Run the quiz
1. Start the quiz
2. On Question 1 choose two checkboxes
3. On question 2 choose one radio button.
4. On question 3 click back
- Note that on question 2 the radio button is checked
5. On question 2 click back
- Note that the checkboxes in question 1 are not checked. (these should be checked)
Proposed solution:
In multichoice.classes.inc::getAnsweringForm().
if (is_array($response->getResponse())) {
$element['#default_value'] = $response->getResponse();
}
Should be:
if (is_array($response->getResponse())) {
$element['user_answer']['#default_value'] = $response->getResponse();
}
I”ve attached a patch with this issue.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | multi_choice_answers-2516782-6.patch | 2.61 KB | djdevin |
| #6 | test.patch | 1.97 KB | djdevin |
Comments
Comment #1
partdigital commentedComment #2
partdigital commentedComment #3
partdigital commentedComment #4
djdevinThanks for the patch, let's write a test to ensure this is broken & fixed.
Comment #5
partdigital commentedRenaming the patch, no code changes made.
Comment #6
djdevinAdded test for restoring multichoice selections.
Comment #7
djdevinComment #9
djdevinFixed, with tests!
Comment #11
Renee S commentedThanks! I'm using 4, is this patch backwards-compatible?
Comment #12
djdevinSorry it's not, 4.x uses a deprecated way of rendering the question form so it's a different approach. It looks like it should have been prefilling already but might require a more involved fix to restore question selections.
Comment #13
Renee S commentedAh, ok, just for history if anybody looks here, turns out I did upgrade to 5.x, so this was not a bug in 4 (that I know of). So, will apply this! And thanks.
Comment #15
tim.plunkett