Coloring Choice and Feedback in quiz question design

Coloring Choice and Feedback in quiz question design

by Oleg Melnikov -
Number of replies: 16

H All. I'm wondering if there is a plugin or a way to distinguish correct/incorrect Choices and Feedback in quiz question edit mode. Currently the All-or-Nothing Multiple Choice Question , Random Answers Select, and a few related question types have similar formatting with gray background for Choice and Feedback sections (see print screen), which makes me confuse them regularly. Also, I occasionally forget to check "Correct" check box. It would be great to have the coloring change from, say, bluish or reddish (for incorrect Choices) to greenish (correct Choices) and leave the Feedback as gray. Anyone knows a way to distinguish these sections?


Average of ratings: -
In reply to Oleg Melnikov

Re: Coloring Choice and Feedback in quiz question design

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello Oleg,

In my opinion, the presentation of the choices and their feedback in these question types should be like that of the multiple choice question, i.e. each choice and its feedback is grouped in a gray block.

Eoin, maintainer of the All-or-nothing multiple choice question, and Joseph, maintainer of the Random select answers question, could probably make the change quickly. You could ask them to do it, here or in a tracker.

In the meantime, you could for example create an html block in the questions (the block will only appear when editing the question), with the following code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
    $("fieldset#id_answerhdr div.fcontainer div.form-group:nth-child(3n+2)").css("background-color","#eee");
    $("fieldset#id_answerhdr div.fcontainer div.form-group:nth-child(3n+2)").css("margin-bottom","0px");
    $("fieldset#id_answerhdr div.fcontainer div.form-group:nth-child(3n+2)").css("border-left","1px solid #bbb");
    $("fieldset#id_answerhdr div.fcontainer div.form-group:nth-child(3n+2)").css("border-right","1px solid #bbb");
});
</script>

Without the script:

MoodleForum_20211120_1250.png

With the script:

MoodleForum_20211120_1251.png
Average of ratings: Useful (1)
In reply to Dominique Bauer

Re: Coloring Choice and Feedback in quiz question design

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

@Dominique,

You were 3 minutes faster than me.Yes

I'll see what I can do for the Random Select Answers question type which I maintain.

Joseph

Average of ratings: Useful (1)
In reply to Joseph Rézeau

Re: Coloring Choice and Feedback in quiz question design

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello Joseph,

My little jQuery code is actually just one line of CSS:

<style>
fieldset#id_answerhdr div.fcontainer div.form-group:nth-child(3n+2) {
    background-color: #eee;
    margin-bottom: 0px;
    border-left: 1px solid #bbb;
    border-right: 1px solid #bbb;
}
</style>
Average of ratings: Useful (1)
In reply to Dominique Bauer

Re: Coloring Choice and Feedback in quiz question design

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

@Dominique "In my opinion, the presentation of the choices and their feedback in these question types should be like that of the multiple choice question, i.e. each choice and its feedback is grouped in a gray block. Eoin, maintainer of the All-or-nothing multiple choice question, and Joseph, maintainer of the Random select answers question, could probably make the change quickly. You could ask them to do it, here or in a tracker."

Quite right, Dominique. I've compared the get_per_answer_fields() function in the edit forms of the multichoice, the answersselect and the multichoiceset question types. It appears that in multichoice the 'fraction' element gets marked with an 'fitem_id_fraction_' ID, which can be targeted with a CSS rule. However, the checkbox element 'correctanswer' doesn't get marked with an ID containing the 'correctanswer' string. Which means it cannot be targeted by a CSS rule.sad

I have found a workaround which I have tested in my own answersselect question type and I have created a Pull Request on Eoin Campbell's github repo with the same workaround, if Eoin cares to implement it. Link to my PR there.

I have pushed the changes to my answersselect question type github repo and will shortly release it on the Moodle plugins repo.

There are 2 changes:

  1. In the edit form, add a 5th parameter (define a class) to $mform->createElement('checkbox', 'correctanswer',
    get_string('correctanswer', 'qtype_answersselect'), '', 'class = "correctanswer"');
  2. In the CSS file create the relevant CSS rule body#page-question-type-answersselect .correctanswer { }

Result:

Average of ratings: Useful (1)
In reply to Dominique Bauer

Re: Coloring Choice and Feedback in quiz question design

by Oleg Melnikov -
Hi Dominique. Need your help with this again smile Something changed in the new version of Moodle and the awesome green highlighting moved from the "Choice" region of the correct answer to the more general "Answers" region. See print screen for clarity. What might need to be modified in the JavaScript/CSS to return the highlighting of the correct answer choices, which was very useful?

P.S. Not sure if this post helps.

print screen of colored area
In reply to Oleg Melnikov

Re: Coloring Choice and Feedback in quiz question design

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Oleg,

You have 2 questions in the same post; it would have been better to post 2 separate posts. Anyway...

#1.- ...a way to distinguish correct/incorrect Choices and Feedback in quiz question edit mode. Currently the All-or-Nothing Multiple Choice Question , Random Answers Select, and a few related question types have similar formatting with gray background for Choice and Feedback sections (see print screen), which makes me confuse them regularly.

#2.- Also, I occasionally forget to check "Correct" check box. It would be great to have the coloring change from, say, bluish or reddish (for incorrect Choices) to greenish (correct Choices) and leave the Feedback as gray. Anyone knows a way to distinguish these sections?

#1.- You could put this CSS rule inside the Advanced Settings of your current Moodle site theme (works for these 2 question types)

body#page-question-type-answersselect [id*="fitem_id_feedback"],
body#page-question-type-multichoiceset [id*="fitem_id_feedback"] {
    background-color: #e2e6ea!important;
}

#2.- This would need a js script, to trigger the colour change upon ticking the Correct choice box. Maybe our friend Dominique can suggest a solution.

Average of ratings: Useful (2)
In reply to Joseph Rézeau

Re: Coloring Choice and Feedback in quiz question design

by Oleg Melnikov -
Thank you all. CSS is an interesting idea, which I will discuss with our Moodle site Admins.
In reply to Oleg Melnikov

Re: Coloring Choice and Feedback in quiz question design

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Oleg,

Regarding the color, in my opinion, grouping each set of Choice, 'Correct' checkbox and Feedback in a gray block, as is done with the multiple choice core question, should be sufficient.

The following code changes the background color of the choices to green when the 'Correct' checkbox is checked. You can try it out for yourself by putting it in a block (no need to ask the site Admins):

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js">
</script>
<script>
$(document).ready(function() {
    // Color according to checkboxes setting
    $("fieldset#id_answerhdr div.fcontainer div.form-group:nth-child(3n+2)").find("input").each(function() {
        if ($(this).prop("checked") == true) {
            $(this).parents().eq(3).prev().css("background-color","#afa");
        }
        else if ($(this).prop("checked") == false) {
            $(this).parents().eq(3).prev().css("background-color","#eee");
        }
    });
    // Color when to checkboxes are checked
    $("fieldset#id_answerhdr div.fcontainer div.form-group:nth-child(3n+2)").find("input").on('click',function() {
        if ($(this).prop("checked") == true) {
            $(this).parents().eq(3).prev().css("background-color","#afa");
        }
        else if ($(this).prop("checked") == false) { 
            $(this).parents().eq(3).prev().css("background-color","#eee");
        }
    });
});
</script>

If this is really useful to you, you can ask the site Admins to integrate the code into the site. They will need to identify the page where the code should be applied, for example by enclosing the code as follows:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js">
</script>
<script>
$(document).ready(function() {
    var a = "Editing an All-or-Nothing Multiple Choice Question";
    var b = "Editing a Random select answers question";
    var c = $(document).find("title").text();
    if ( c == a || c == b ) {
        // Color according to checkboxes setting
        $("fieldset#id_answerhdr div.fcontainer div.form-group:nth-child(3n+2)").find("input").each(function() {
            if ($(this).prop("checked") == true) {
                $(this).parents().eq(3).prev().css("background-color","#afa");
            }
            else if ($(this).prop("checked") == false) {
                $(this).parents().eq(3).prev().css("background-color","#eee");
            }
        });
        // Color when to checkboxes are checked
        $("fieldset#id_answerhdr div.fcontainer div.form-group:nth-child(3n+2)").find("input").on('click',function() {
            if ($(this).prop("checked") == true) {
                $(this).parents().eq(3).prev().css("background-color","#afa");
            }
            else if ($(this).prop("checked") == false) { 
                $(this).parents().eq(3).prev().css("background-color","#eee");
            }
        });
    }
});
</script>

I don't think CSS is enough to change the color when you click the 'Correct' checkbox. The code is therefore in jQuery (JavaScript). Site Admins can easily integrate it into Site adminstration / Appearance / Additional HTML.

Average of ratings: Useful (2)
In reply to Dominique Bauer

Re: Coloring Choice and Feedback in quiz question design

by Oleg Melnikov -
Dominique, thanks! The coloring looks great. What is a "block" where I can add this script to? I Googled it; and it seems that scripts/CSS can be added to HTML block, but this type of block is missing from my course. I'm wondering if it's disabled (or not installed) by the admin or if it's something I can enable myself.
In reply to Oleg Melnikov

Re: Coloring Choice and Feedback in quiz question design

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Oleg,

Follow these steps:

  1. On the main page where the quiz is located, click on "Turn editing on" if it is not already done.
  2. Click on the quiz.
  3. From the cogwheel icon, select "Edit Quiz".
  4. Click on a question.
  5. At the top left of the page, click on the hamburger icon to display the left menu.
  6. In the left menu, select "Add a block" located at the bottom of the menu.
  7. In the "Add a block" pop-up window, select HTML.
  8. Depending on the width of the screen, you will see the "(new HTML block)" block on the right or bottom of the screen.
  9. Click on the "(new HTML block)" block's gear icon and select "Configure (new HTML block) block".
  10. Give a name to the "HTML block title".
  11. If you are using the Atto editor, click on the </> HTML button of the "Content" field to put the editor in HTML mode (in which the lines are numbered).
  12. Paste the code in the "Content" field.
  13. Set "Display on page types" to "Any question page".
  14. Click on "Save changes".

That's it. If you don't see the "Add a block" (step 6) or "HTML" (step 7) selection, they have probably been disabled by your site administrator. You can request that they be reactivated as they are useful to teachers and do not pose any safety concerns.

I used the color #afa (short for #aaffaa), a fairly light green. For other colors, see for example W3Schools ↗.

Average of ratings: Useful (2)
In reply to Dominique Bauer

Re: Coloring Choice and Feedback in quiz question design

by Oleg Melnikov -
Dominique, thank you for the detailed instructions. I followed it to (7), where I could not find HTML block again smile I see other block types (Activity results, Administration, Blog menu, Blog tags, Comments, ..., Tags), but HTML block is not listed. I'm guessing that I need to reach out to site's Admin to activate HTML block.
In reply to Dominique Bauer

Re: Coloring Choice and Feedback in quiz question design

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

@Dominique,

Any idea how I could incorporate your "colouring" script directly into my answersselect question type?

Joseph

In reply to Joseph Rézeau

Re: Coloring Choice and Feedback in quiz question design

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

@Joseph,

A priori, I do not know but I will look at this. Do you think it's a good idea to add color? Shouldn't the layout be uniform and similar to the core multiple-choice question?

In reply to Dominique Bauer

Re: Coloring Choice and Feedback in quiz question design

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Oleg,

You can find useful information about HTML blocks at https://docs.moodle.org/en/HTML_block ↗

Average of ratings: Useful (1)
In reply to Dominique Bauer

Re: Coloring Choice and Feedback in quiz question design

by Oleg Melnikov -
Dominique, thank you. I sent a request to our admins to enable HTML block , if possible.
In reply to Dominique Bauer

Re: Coloring Choice and Feedback in quiz question design

by Oleg Melnikov -
Thank you all. Our admins added HTML Block and the script runs great in it!
Average of ratings: Useful (1)