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.

Comments

partdigital’s picture

Issue summary: View changes
partdigital’s picture

Issue summary: View changes
partdigital’s picture

Issue summary: View changes
djdevin’s picture

Issue tags: +needs test

Thanks for the patch, let's write a test to ensure this is broken & fixed.

partdigital’s picture

StatusFileSize
new964 bytes

Renaming the patch, no code changes made.

djdevin’s picture

StatusFileSize
new1.97 KB
new0 bytes

Added test for restoring multichoice selections.

djdevin’s picture

StatusFileSize
new2.61 KB

The last submitted patch, 6: test.patch, failed testing.

djdevin’s picture

Status: Needs review » Fixed

Fixed, with tests!

  • djdevin committed 3cfb877 on 7.x-5.x authored by partdigital
    Issue #2516782 by djdevin, partdigital: Multi-choice answers checkbox...
Renee S’s picture

Thanks! I'm using 4, is this patch backwards-compatible?

djdevin’s picture

Sorry 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.

Renee S’s picture

Ah, 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

tim.plunkett’s picture

Issue tags: -needs test