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?
Re: Coloring Choice and Feedback in quiz question design
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:
With the script:
Re: Coloring Choice and Feedback in quiz question design
@Dominique,
You were 3 minutes faster than me.
I'll see what I can do for the Random Select Answers question type which I maintain.
Joseph
Re: Coloring Choice and Feedback in quiz question design
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>
Re: Coloring Choice and Feedback in quiz question design
@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.
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:
- In the edit form, add a 5th parameter (define a class) to $mform->createElement('checkbox', 'correctanswer',
get_string('correctanswer', 'qtype_answersselect'), '', 'class = "correctanswer"'); - In the CSS file create the relevant CSS rule body#page-question-type-answersselect .correctanswer { }
Result:
Re: Coloring Choice and Feedback in quiz question design
Re: Coloring Choice and Feedback in quiz question design
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.
Re: Coloring Choice and Feedback in quiz question design
Re: Coloring Choice and Feedback in quiz question design
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.
Re: Coloring Choice and Feedback in quiz question design
Re: Coloring Choice and Feedback in quiz question design
Oleg,
Follow these steps:
- On the main page where the quiz is located, click on "Turn editing on" if it is not already done.
- Click on the quiz.
- From the cogwheel icon, select "Edit Quiz".
- Click on a question.
- At the top left of the page, click on the hamburger icon to display the left menu.
- In the left menu, select "Add a block" located at the bottom of the menu.
- In the "Add a block" pop-up window, select HTML.
- Depending on the width of the screen, you will see the "(new HTML block)" block on the right or bottom of the screen.
- Click on the "(new HTML block)" block's gear icon and select "Configure (new HTML block) block".
- Give a name to the "HTML block title".
- 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).
- Paste the code in the "Content" field.
- Set "Display on page types" to "Any question page".
- 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 ↗.
Re: Coloring Choice and Feedback in quiz question design
Re: Coloring Choice and Feedback in quiz question design
@Dominique,
Any idea how I could incorporate your "colouring" script directly into my answersselect question type?
Joseph
Re: Coloring Choice and Feedback in quiz question design
@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?
Re: Coloring Choice and Feedback in quiz question design
Oleg,
You can find useful information about HTML blocks at https://docs.moodle.org/en/HTML_block ↗