Formulas - hide answer box

Formulas - hide answer box

by Marko Nuskol -
Number of replies: 2

Here I am, once again, with another conundrum 😎

Recently we have installed Embed question filter (https://moodle.org/plugins/filter_embedquestion) into our Moodle v3.9.

This has opened new possibilities of embedding question anywhere we like (whether inside Page or Homework) - we are not limited to just quiz anymore! Great feature 🤠

The question / help I need is how to hide answer box inside a question.

What I want is to give our students a homework. But for every student I want random / different numbers (which I can do easily inside Formulas). I don't want them to be able to give the answer (which will be just number 1) and the next time they open this homework they will have different set of data.

Hope you can understand what I want. Just the ability to hide the answer box so they cannot answer this question and change the data they get.

I will attach the screenshot (I need the white box to be hidden)


Much appreciated

Attachment Screenshot_1.jpg
Average of ratings: -
In reply to Marko Nuskol

Re: Formulas - hide answer box

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

Hello Marko,

You can hide the answer box using <style>, JavaScript or jQuery. The easiest way is to use <style>, but the Atto editor automatically removes it. The "Plain text area" editor keeps the <style>, but you will lose it as soon as you inadvertently edit the question with the Atto editor. For this reason and because jQuery is simple and works well, I suggest using jQuery.

You probably don't want to hide answer boxes in all of your quizzes. You should therefore not place the following code in Site administration / Appearance / Additional HTML /.., but rather in the HTML of the question text of the question you want to modify.

The code is as follows:

<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script>
$(document).ready (function(){
    $(".formulas_number").css("display","none");
});
</script>

where ".formulas_number" is the element whose class, identified by ".", is "formulas_number". To identify the element you want to hide, in this case the answer box, place the cursor in the answer box and, if you're using Chrome, right-click and select "Inspect". You will then see in the right panel that it is an "input" element whose class is "formulas_number". It is therefore this element that will be hiden with the code above.

I leave it to you as an exercise to add a line to hide the "Check" button and another to hide the block for the mark.

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

Re: Formulas - hide answer box

by Marko Nuskol -
Dear Dominique,

The code works! It is amazing what a little coding can do 👨‍💻

I have successfully hidden the "Check" button and the block for the mark.
When I get some free time, I should try learning JQuery. Up till now it has aided me many times (for calculated questions and graphs in Formulas).

Thank you for the swift reply and continued help.

With regards,

Marko Nuskol
Attachment Screenshot_1.png