Moodle

Pressing enter when answering a short answer question can submit the wrong one

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.6, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.7, 1.7.1, 1.8, 1.9
  • Fix Version/s: 1.8.3, 1.9
  • Component/s: Questions, Quiz
  • Labels:
    None
  • Affected Branches:
    MOODLE_16_STABLE, MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_18_STABLE, MOODLE_19_STABLE

Description

On a quiz page, if there are more than one questions where the input is a text field (as in SHORTANSWER questions), pressing the Enter key will submit the whole form, which is not a good idea. Look at this scenario.

Quiz settings: Adaptive mode Yes. / Students may review everything at any time, except for the correct answers (only available after quiz is closed).
Quiz with 2 shortanswer questions on page, Q1 and Q2

Student enters nothing in Q1 but enters a response in Q2, and then presses the Enter key
Moodle reaction -> Only Q1 is analysed, it is found empty and is graded accordingly, this message is displayed:
Incorrect
Marks for this submission: 0/1. This submission attracted a penalty of 0.1.
Nothing is displayed concerning Q2 where the student entered his response... which is puzzling to him.
It looks to me that in fact pressing the Enter key is equivalent to clicking the Submit page button.
Of course the students should be told NOT to use the Enter key to submit their responses but to click the individual Submit buttons but... it would be better is this was taken care of by the program itself!

I do hope some solution will be found for this problem, if not for 1.7 at least for 1.8 or 1.9 versions,

Joseph

Activity

Hide
Tim Hunt added a comment -

As suggested, the solution is some JavaScript to stop the enter key having an effect.

On a suitable element (the form?) add onkeypress="return check_enter(event);"

and in some JavaScript function, define the check_enter function:

function checkEnter(e) {
var target = e.target ? e.target : e.srcElement;
var keyCode = e.keyCode ? e.keyCode : e.which;

// Stifle Enter on anything except submit buttons and textareas
if(keyCode==13 && (Unable to render embedded object: File (target.type ) not found.='submit' && target.type!='textarea')))
return false;
else
return true;
}

(That solution is courtesy of OpenMark.) I need to check that this works with the HTML editor in essay questions.

Unfortunately, there is nothing you can do about this when JavaScript is turned off.

Show
Tim Hunt added a comment - As suggested, the solution is some JavaScript to stop the enter key having an effect. On a suitable element (the form?) add onkeypress="return check_enter(event);" and in some JavaScript function, define the check_enter function: function checkEnter(e) { var target = e.target ? e.target : e.srcElement; var keyCode = e.keyCode ? e.keyCode : e.which; // Stifle Enter on anything except submit buttons and textareas if(keyCode==13 && (Unable to render embedded object: File (target.type ) not found.='submit' && target.type!='textarea'))) return false; else return true; } (That solution is courtesy of OpenMark.) I need to check that this works with the HTML editor in essay questions. Unfortunately, there is nothing you can do about this when JavaScript is turned off.
Hide
Tim Hunt added a comment -

Fix implemented as described in the last comment.

Show
Tim Hunt added a comment - Fix implemented as described in the last comment.
Hide
Pierre Pichet added a comment -

The problem is related to the fact that when you click on the enter key, the default active submit button is the last one encounter on the page or if there is no other submit button the next one.
On a simple quiz containing two questions if you use the preview function the submit buttons encountered are
<start again>
[question 1 text input]
<submit>
[question 2 text input]
<submit>
So if to type enter in [question 1 text input] you (or the default HTML functionning) will activate the <start again> but not submit the question1
if you o type enter in [question 2 text input] you will (or the default HTML functionning) will activate the <submit > of question 1 but not submit the question2 and so on.
The best way to solve the problem without javascript is to have 2 <submit>buttons for each question, one at the beginning and one at the end.
So if you type the enter key anyplace between these two submits ( for example in a cloze question) the question will be the one submitted.
However this will change the usual quiz display but this can be managed.

Show
Pierre Pichet added a comment - The problem is related to the fact that when you click on the enter key, the default active submit button is the last one encounter on the page or if there is no other submit button the next one. On a simple quiz containing two questions if you use the preview function the submit buttons encountered are <start again> [question 1 text input] <submit> [question 2 text input] <submit> So if to type enter in [question 1 text input] you (or the default HTML functionning) will activate the <start again> but not submit the question1 if you o type enter in [question 2 text input] you will (or the default HTML functionning) will activate the <submit > of question 1 but not submit the question2 and so on. The best way to solve the problem without javascript is to have 2 <submit>buttons for each question, one at the beginning and one at the end. So if you type the enter key anyplace between these two submits ( for example in a cloze question) the question will be the one submitted. However this will change the usual quiz display but this can be managed.
Hide
Joseph Rézeau added a comment -

Pierre > "The best way to solve the problem without javascript is to have 2 <submit>buttons for each question, one at the beginning and one at the end. "
I disagree; there are far too many buttons on the Quiz screen (especially in Adaptive mode) at the moment, we certainly do not want the interface to be MORE cluttered! I think that Tim's de-activating of the Enter key is a good workaround.
Joseph

Show
Joseph Rézeau added a comment - Pierre > "The best way to solve the problem without javascript is to have 2 <submit>buttons for each question, one at the beginning and one at the end. " I disagree; there are far too many buttons on the Quiz screen (especially in Adaptive mode) at the moment, we certainly do not want the interface to be MORE cluttered! I think that Tim's de-activating of the Enter key is a good workaround. Joseph
Hide
Pierre Pichet added a comment -

This is not completely exact, I was mixed up by the fact the question grade was fixed to maximum score and that I tested it with just two questions
On a closer look at the HTML code the <start again> is in a different <form> than the questions <form>.
So the more exact way the system works is that if you type the enter key in the question 1 text field the question 1 is graded.
If you type the enter key in the question 2 text field the question 1 is graded.
If you type the enter key in the question 3 text field the question 1 is graded.
And so on.
As for my proposal ...
Is there a way to deactivate the enter key without javascript because javascript is not always activated and as the quiz is often part of the student evaluation, it should be "fullproof" ?

Show
Pierre Pichet added a comment - This is not completely exact, I was mixed up by the fact the question grade was fixed to maximum score and that I tested it with just two questions On a closer look at the HTML code the <start again> is in a different <form> than the questions <form>. So the more exact way the system works is that if you type the enter key in the question 1 text field the question 1 is graded. If you type the enter key in the question 2 text field the question 1 is graded. If you type the enter key in the question 3 text field the question 1 is graded. And so on. As for my proposal ... Is there a way to deactivate the enter key without javascript because javascript is not always activated and as the quiz is often part of the student evaluation, it should be "fullproof" ?
Hide
Tim Hunt added a comment -

Javascript is the only way to disable the enter key. About 95% of people have Javascript on. (http://www.thecounter.com/stats/2007/September/javas.php). For those that don't, the situation is no worse that it was before, they just need to learn not to press enter. Considering how few reports of this problem we got, I would say that very few people do anyway.

Show
Tim Hunt added a comment - Javascript is the only way to disable the enter key. About 95% of people have Javascript on. (http://www.thecounter.com/stats/2007/September/javas.php). For those that don't, the situation is no worse that it was before, they just need to learn not to press enter. Considering how few reports of this problem we got, I would say that very few people do anyway.
Hide
Joseph Rézeau added a comment -

Tim > Javascript is the only way to disable the enter key. About 95% of people have Javascript on.
Yes, I often wonder how on earth one can navigate the Internet and, more specifically, how one can use Moodle without Javascript ON...

>For those that don't, the situation is no worse that it was before, they just need to learn not to press enter. Considering how few reports of this problem we got, I would say that very few people do anyway.
I expect it's advanced users (like... ourselves) who tend to favour using the keyboard over using the mouse whenever possible and "normal" users who will use the mouse.

Show
Joseph Rézeau added a comment - Tim > Javascript is the only way to disable the enter key. About 95% of people have Javascript on. Yes, I often wonder how on earth one can navigate the Internet and, more specifically, how one can use Moodle without Javascript ON... >For those that don't, the situation is no worse that it was before, they just need to learn not to press enter. Considering how few reports of this problem we got, I would say that very few people do anyway. I expect it's advanced users (like... ourselves) who tend to favour using the keyboard over using the mouse whenever possible and "normal" users who will use the mouse.
Hide
Tim Hunt added a comment -

I just backported this fix to Moodle 1.8.

Show
Tim Hunt added a comment - I just backported this fix to Moodle 1.8.
Hide
Oleg Sychev added a comment -

I still have this problem during teacher's preview of quiz in 1.9 Stable with javascript on.

Show
Oleg Sychev added a comment - I still have this problem during teacher's preview of quiz in 1.9 Stable with javascript on.
Hide
Tim Hunt added a comment -

OK, my commit on 12th Dec broke this. Fixed again now.

Show
Tim Hunt added a comment - OK, my commit on 12th Dec broke this. Fixed again now.
Hide
Joseph Rézeau added a comment -

Disabling Enter key in quiz: works OK on 1.9, still does not work on 1.8.
Joseph

Show
Joseph Rézeau added a comment - Disabling Enter key in quiz: works OK on 1.9, still does not work on 1.8. Joseph
Hide
Tim Hunt added a comment -

Please be more specific!

Show
Tim Hunt added a comment - Please be more specific!
Hide
Joseph Rézeau added a comment -

One suggestion:
Users who are used to pressing the Enter key after filling in an input text zone might be surprised that the Enter key is now inactive. What about adding a message to tell them to click the Submit button instead?
something like:
function check_enter(e) {
var target = e.target ? e.target : e.srcElement;
var keyCode = e.keyCode ? e.keyCode : e.which;
if (keyCode==13 && target.nodeName!='a' &&
(!target.type || !(target.type=='submit' || target.type=='textarea'))) { alert("Please click the Submit button"); return false; } else { return true; }
}
But I do not know how the hardcoded alert message could be made a language string here.
Joseph

Show
Joseph Rézeau added a comment - One suggestion: Users who are used to pressing the Enter key after filling in an input text zone might be surprised that the Enter key is now inactive. What about adding a message to tell them to click the Submit button instead? something like: function check_enter(e) { var target = e.target ? e.target : e.srcElement; var keyCode = e.keyCode ? e.keyCode : e.which; if (keyCode==13 && target.nodeName!='a' && (!target.type || !(target.type=='submit' || target.type=='textarea'))) { alert("Please click the Submit button"); return false; } else { return true; } } But I do not know how the hardcoded alert message could be made a language string here. Joseph
Hide
Tim Hunt added a comment -

Now fixed again. The JavaScript function was being defined inside a PHP if statement. How embarassing. And no wonder I moved the JavaScript into a separate file in 1.9.

I really don't like the alert idea. 99% of the time it would just annoy people. 1% of the time it might help. But I think if pressing enter does not work, people will naturally go to the submit button.

Show
Tim Hunt added a comment - Now fixed again. The JavaScript function was being defined inside a PHP if statement. How embarassing. And no wonder I moved the JavaScript into a separate file in 1.9. I really don't like the alert idea. 99% of the time it would just annoy people. 1% of the time it might help. But I think if pressing enter does not work, people will naturally go to the submit button.
Hide
Pierre Pichet added a comment -

I agree with Tim.
Consider also that when there are multiple input fields which is normally the case with quizzes, you don't use the enter key until your at the end of the page.

Show
Pierre Pichet added a comment - I agree with Tim. Consider also that when there are multiple input fields which is normally the case with quizzes, you don't use the enter key until your at the end of the page.
Hide
Joseph Rézeau added a comment -

Pierre > Consider also that when there are multiple input fields which is normally the case with quizzes, you don't use the enter key until your at the end of the page.
I don't, but my students do it (all the time).
Joseph

Show
Joseph Rézeau added a comment - Pierre > Consider also that when there are multiple input fields which is normally the case with quizzes, you don't use the enter key until your at the end of the page. I don't, but my students do it (all the time). Joseph

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: