How to force re-grading questions even when answer is unchanged

How to force re-grading questions even when answer is unchanged

de Richard Lobb -
Número de respuestas: 0

A user posted a question on github, asking if there was a way to ensure that CodeRunner regraded question even when answers haven't changed. Their use-case was rather unusual - the student answer was not actually present in the answer box at all but was being fetched from a remote server. The answer itself was a dummy that didn't change.

In case there are any other users with similar use cases, I'm posting my answer here, though it hasn't had much testing ...

I think your problem can be solved by adding to the end of the question itself (editing n HTML mode) something like the following code:

<p>
<script>
    const currentScript = document.currentScript;
    document.addEventListener('DOMContentLoaded', function() {
        // Find the formulation div that contains the current script.
        const formulationDiv = currentScript.parentElement.parentElement;
        const buttons = formulationDiv.getElementsByClassName('submit');
        const answerTextArea = formulationDiv.getElementsByClassName(
            'coderunner-answer')[0];
        for (let i = 0; i < buttons.length; i++) {
            buttons[i].addEventListener('click', function(event) {
                // Add a random comment string at the end of the Python code.
                answerTextArea.value += `\n#${Math.random()}`;
            });
        }
    });
</script>
</p>

This works with the one simple test I did using a Python3 question type but might need to be modified if you have your own UI plugin. Also, there might be a race problem (with very low probability) if you use this with a UI plugin that depends on the sync method to update the serialisation in the (hidden) answer box text area.