Follow up on "Grading criteria checkbox not displayed in Boost theme"

Follow up on "Grading criteria checkbox not displayed in Boost theme"

by Dominique Bauer -
Number of replies: 18
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

This bug was reported some time ago in the post: https://moodle.org/mod/forum/discuss.php?d=345283#p1392516 

Fixing it would help me complete the documentation on the manual Grading criteria (https://docs.moodle.org/33/en/Formulas:_Answers_and_marking#Manual_grading_criteria) and would encourage people to use this nice feature of the Formulas question type.

Average of ratings: -
In reply to Dominique Bauer

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

by Jean-Michel Védrine -

Hello Dominique

Thanks a lot for bringing my attention on that message because I missed it !

That checkbox is managed by the editing.js script and if I remember well I have already fixed it several times because it is very prone to break.

I will try to find a solution that works for all themes. Unfortunately as I said several times my javascript knowledge is not very good !

By the way it would help me if people finding bugs or problems in the formulas and algebra questions types, the Question Creation activity module and the Gift with medias import format could open a tracker issue because I am not sure I see all related posts in the forum.

I will verify that these plugins documentations have a working link to the tracker.

In reply to Jean-Michel Védrine

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

by Jean-Michel Védrine -

Maybe I should first explain how i is (should) be working because for young Moodle users that only know the Boost theme (by the way to test this I changed my theme to More and I must admit that since I stopped using Moodle 2 years ago,  I was not remembering how cool it was compared to Boost in term of usability !) they never have see it working

The Grading criteria has two forms:

Formula question grading criteria easythat we can call the "Easy" mode

Formula question gradin criteria expertthat we can call the "Expert" mode

In the Easy mode you can choose Relative/Absolute error Inferior/egal comparator and type a value to be used

This needs no explanation if your answer has only one dimension.

But don't forget that a formulas answer can be multidimensional so in that case it's uneasy to explain how the comparison is done without using some mathematical background

Take for instance that the correct answer has 2 values [a, b] and the student answer is [c, d], the absolute error will be

\( \sqrt{(a-c)^2+(b-d)^2} \) and Il will let mathematical readers guess what is the relative error not to frighten too much everybody wink

Of course during that comparison if different units were used for the correct and student answers (for instance the correct answer was 2 m and the student answer is 199 cm) a conversion to a common unit is done.

So let's think that everybody understand the easy mode.

And for the "Expert" mode ? 

For now I will just say that you have to enter an expression in the text field and that this expression must give a result between 0 and 1, 0 meaning completely wrong and 1 absolutely correct.

To build that expression you can use different variables

  • the correct answer _a
  •  the student answer _r and it's coordinates _0, _1, _2, ...
  • the absolute error _err and the relative error _relerr (not defined for algebraic answers)
Last thing is that I think the current UI (even if it was working) is not very good. Now with Bootstrap and all the niceties in Moodle recent versions I think we can devise a better UI.

In reply to Jean-Michel Védrine

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

by Bernat Martinez -
Hi Jean-Michel,


In order to keep using Boost I used the  workaround  

"initial_checked = true" in line 193, in "formulas/script/editing.js"

In this way you are using always the expert mode, but maybe a better solution could be find

Average of ratings: Useful (1)
In reply to Bernat Martinez

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

by Jean-Michel Védrine -

Hello Bernat,

Of course it is easy to always have either the "Easy" or the "Expert" mode on. But I would prefer to fix the bug.

In fact according to my first experiments all the javascript is nearly working.

The problem is this line https://github.com/jmvedrine/moodle-qtype_formulas/blob/master/script/editing.js#L213 that try to insert the correct javascript at the correct place in the page and that is failing in Boost.

Of course navigating like that in the HTML tree is very hacky and prone to break if the tree change !

So I must change the way it is done, to find a method working for all themes.

By the way there is a lot of cleaning to do in that script because a lot of the functions here are no more used.

The only interesting parts of editing.js now are the functions for the grading criteria and the functions to instantiate the datasets (that are broken in all themes I tried !)

In reply to Jean-Michel Védrine

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

by Jean-Michel Védrine -

I think that an UI with a button like that could be neater (it's just a mockup done in Paint I have nothing working !)

New formulas grading criteria UI 1

New formulas grading criteria UI 2

What do you think of it ?

If this was in the "main" part of the question form it would be quite simple, but as it is in the "answer" part, I need to remember how the add_per_answer_fields/get_per_answer_fields are working.

Average of ratings: Useful (1)
In reply to Jean-Michel Védrine

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

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

Jean-Michel,

Do you have the Expert mode and Easy mode buttons the right way around? Anyhow, I think that these buttons are not really necessary. The first field could be simply called "Grading criterion", singular not plural, and the second field "Custom grading criteria", plural as there may be more than one criterion in that field.

The display of the two fields should be mutually exclusive, i.e. "Grading criterion" must be active when "Custom grading criteria" is empty, and "Grading criterion" must become inactive and grayed out when "Custom grading criteria" is filled out. (At least according to the current operation of the Editing page.)

Otherwise, I think that your suggestion is perfect.

In reply to Dominique Bauer

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

by Jean-Michel Védrine -

My idea for the buttons is that when you are in the Easy mode the button switch to the Expert mode and vice versa. Is that confusing

Your idea would need some more work on the javascript as internally "Custom grading criteria" is never empty and in fact it's the one that is saved in the database. In easy mode it is simply hidden.

The "Grading criterion" display is entirely created by the script and the script do the traduction between both displays.

There are some subtleties : try something (using some theme where it is working, for instance More) : type something more complex in the "Expert mode" and switch to "Easy mode" as the translation can't be done, the criterion is reverted to the default one. But if you type _relerr < 0.5 in the Expert mode this is correctly translated in the Easy mode when you switch.

I think nobody can imagine how many hours I spent studying Hon Wai Lau's complex code !

In reply to Jean-Michel Védrine

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

by Jean-Michel Védrine -

I think I have fixed the "Check variables instantiation" feature in the question  edit page.

It  was just needing a few lines changes in  the  instantiate.php file. A corrected version is in my Github.

Can somebody try if my fix is working for him ? Of course you need some formulas questions with random variables to test it smile.

I was loving this feature when I was using formulas questions with students as it permit you to verify that your random variables dataset only produce suitable values for all other variables and answers.

Check variables instantiation

In reply to Jean-Michel Védrine

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

by Bernat Martinez -

Sorry, Jean-Michel, maybe I don't understand your post,  but for me the Check variables instantiation seems to be working as it is now


Attachment Captura de pantalla 2018-01-23 a les 6.58.03.png
In reply to Bernat Martinez

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

by Jean-Michel Védrine -

Well, it was working, then it stopped working a few weeks ago when I tried to improve security of the communication with the instantiate.php script after reading the results from my Travis job.

I think that my last version, now in my Github is both more secure and working. 

As I don't really know if in the version available from the plugin directory the Check variables instantiation is working or not I will release a new one very soon, and it will be advertised as security release rather than maintenance release (hint).

I have also corrected some links to Dominique superb documentation and corrected criteria/criterion.

The last thing I need to do is to have the Simple/Expert correctness working.

In reply to Jean-Michel Védrine

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

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

Hi Jean-Michel,

I think nobody can imagine how many hours I spent studying Hon Wai Lau's complex code ! I did a little bit of programming a long time ago. Once, I had to work on a colleague's poor code, it was a nightmare. For its part, HonWai's code is probably excellent but very complex. I understand that he took about a year to write the plugin. I would not be surprised if one year of his work meant about 300 days at 16 hours/day for a total of close to 5000 hours. In order to really grasp another person's complex code, an expert programmer would take in reality, imho, 3 to 5 times the amount of time it took to write the code originally. So, I would estimate that you spent about 20000 hours. Am I close?

The fact is that without you, the Formulas plugin would have not survived Moodle 2.0. And I think that everybody will agree with me that you did a fantastic job and that we are all very thankful for upgrading and maintaining the plugin for all those years.

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

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

by Jean-Michel Védrine -

Well in fact it was surely the greatest experience of my life as an amateur développer.

I am totally unable to estimate the number of hours it took me.

Sometime I was really desperate and thinking I would never succeed. I emailed Tim many times asking for advice, and also to Hon Wai Lau to ask for explanations.

I remember a funny thing : at some sage I was completely blocked, so I stopped all work for nearly a month, then one night I awoke and it was completely clear in my mind so fearing to loose it, I immediately went to my computer to code the solution and bingo it was working.

In reply to Jean-Michel Védrine

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

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

My idea for the buttons is that when you are in the Easy mode the button switch to the Expert mode and vice versa. Is that confusing ? Your idea would need some more work on the javascript as internally "Custom grading criteria" is never empty and in fact it's the one that is saved in the database. In easy mode it is simply hidden.

Do whatever is easier. I don't expect the two buttons to be too confusing.

There are some subtleties : try something (using some theme where it is working, for instance More) : type something more complex in the "Expert mode" and switch to "Easy mode" as the translation can't be done, the criterion is reverted to the default one. But if you type _relerr < 0.5 in the Expert mode this is correctly translated in the Easy mode when you switch.

Today I wrote a more complex criterion in Moodle 3.3 under the Clean theme: (_0 == a && _1 == b) || (_0 == b && _1 == a) meaning that two answers can be given as a and b, or b and a. I then reverted to Boost: the complex criterion was kept as it, I could even edit it and the question functions well with the complex criterion under Boost. 

In reply to Dominique Bauer

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

by Jean-Michel Védrine -

Hello Dominique,

As I said only the display of the checkbox is broken.

If you edit the script/editing.js file commenting the 2 lines

       n.style.display = use_raw_input ? 'block' : 'none';

        b.style.display = use_raw_input ? 'none' : 'block';

(Don't forget to purge all caches)

Then both the fields for simple and expert mode will be visibles

And you will see that the update works in both directions even in Boost.

So I must be stupid because all my tries to have a checkbox or a button visible in all themes and browsers have been unsuccessful so far. 

I am surely missing something.

In reply to Jean-Michel Védrine

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

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

Jean-Michel,

Personally, I'm not yet familiar with the Moodle code and I'm not a big help when it comes to programming.

In the pages for editing quizzes and questions of different types, there are many check boxes, pull-down menus and active/inactive grayable fields. Is this one much different?

In reply to Jean-Michel Védrine

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

by Bernat Martinez -

It works,  See 2 attachments, 

First both modes (simple and expert) are displayed 

Second when the grading criteria  is edited the simple mode disappears.


Attachment Screen Shot 2018-01-28 at 00.35.31.png
Attachment Screen Shot 2018-01-28 at 00.42.50.png
In reply to Bernat Martinez

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

by Jean-Michel Védrine -

Well I think I will release this as it is now, I have already spend too much time on that damned checkbox !

With the latest version that is now in my github repo the checkbox seems to be working in all themes and browsers that I have tried.

The problem is that it is not showing at the right place so it "push" the fields below

Display with the box checked:

formulas grading criteria 1

and if you uncheck the box:

formulas grading criterion 2

I have tried multiple variations without any succes

Most probably my error is in the place where I am inserting the checkbox 

        var n = document.getElementById('id_correctness_' +i);
        loc = n.parentNode
        while(!loc.classList.contains("fitem")) {
            loc = loc.parentNode;
        }

        var showid = 'id_correctness_' + i + '_show';
        var b = document.getElementById(showid);
        if (b == null) {
            var tmp = document.createElement('div');
            tmp.id = showid;
            tmp.classList.add('formulas_correctness_show');
            b = loc.insertBefore(tmp, loc.firstChild);
        }

or in the CSS that I just created for it

/* Styles for the editing form. */
body#page-question-type-formulas .formulas_correctness_show {
    display: inline;
    width: 15px;
}

But you can see that I have improved the display of the selects and text field so that they match the other elements of the form

If somebody has some knowledge of HTML and CSS and can give me a clue about the place in the DOM or the CSS styles that I should use, don't hesitate you don't need any javascript or php skill to help me if you can inspect the page elements in the console and tell me what I am doing wrong no problem for me to modify the script accordingly.

In reply to Jean-Michel Védrine

Re: Follow up on "Grading criteria checkbox not displayed in Boost theme"

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

Jean-Michel,

Are all elements, that must appear on the same line, enclosed with <tag style="display:inline;"><tag> or have the display:inline property?