Welcome to CodeRunner; sorry about the frustrations. [I should explain to anyone else reading this that Michel is at UK Open University, where they're running the latest development version of CodeRunner, a.k.a. the version 3.1 Release Candidate. This version runs the sample answer, if given, as part of the form validation process. Earlier versions didn't do that, requiring authors to manually check that their sample answer passed the tests.]
When Moodle questions are saved, the question type plug-in's form validation method is called. It returns a list of errors associated with different parts of the form. Any errors abort the save and instead the form is re-displayed, with errors messages shown in red at the appropriate places in the form. So what you're seeing is the standard Moodle question-save behaviour. However, a local user has also complained about it, so I think it's clear that with a complex question type like CodeRunner the standard behaviour is no longer appropriate. The question is: what to do about it?
I'm quite sure that having the ability to check the sample answer while saving is a step forward (it was done at the request of the community), but it looks like the way it's handed needs to be improved. I'd like to involve Tim Hunt in the discussion, assuming he's tuned in, as some of the approaches require changes to the Moodle question engine rather than to CodeRunner.
Here are some possibilities:
- There's a "Validate on Save" checkbox associated with the sample answer. It currently defaults to "Yes". A trivial change would be to set the default to "No". Perhaps we should do this anyway, Tim, until we have a better UI solution?
- If a save is aborted due to a validation failure, the re-displayed form should be scrolled so that the first error message, in red, is in the window. AFAIK, this isn't something I can control from within CodeRunner, however.
- As Michel suggests, I could pop up a dialogue box whenever a Save is aborted, warning the user. [I think I've seen something in the Moodle API that allows PHP code to trigger an Alert box, though I've never used it. I'll look into that.]
- The recently-added Moodle standard "Save changes and continue editing" button is useful but is also, I think, part of the problem. When there was just a Save button, either the Save worked, taking you back into the question bank, or it failed, taking you back into the form. This gave a fairly clear indication of success or failure. But the new button takes you back into the form regardless, so you don't actually know if the Save succeeded. The previous 2 suggestions would help a lot here, but I wonder if it's even appropriate to be doing form validation when the author has clearly signalled that the question is incomplete, anyway? Should the framework be changed to bypass form validation in this case?
As a workaround until we've come up with a better solution, Michel, I suggest that you hold off entering a sample answer until you've got the rest of the question written or that you uncheck the Validate On Save box prior to every non-final Save.
Thanks for the feedback.