From 10de1a7de7e6855c6c84933618aa84d20f7f07b9 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 7 Feb 2020 21:17:29 +0100 Subject: [PATCH] feat(exam-correct): submit on enter --- frontend/src/utils/exam-correct/exam-correct.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/frontend/src/utils/exam-correct/exam-correct.js b/frontend/src/utils/exam-correct/exam-correct.js index 3c9a1c9f0..e321c6e8a 100644 --- a/frontend/src/utils/exam-correct/exam-correct.js +++ b/frontend/src/utils/exam-correct/exam-correct.js @@ -90,6 +90,10 @@ export class ExamCorrect { deleteBox.addEventListener('change', (() => { this._updatePartDeleteDisabled(deleteBox); }).bind(this)); } + for (let input of [this._userInput, ...this._partInputs]) { + input.addEventListener('keypress', this._inputKeypress.bind(this)); + } + if (!this._userInputStatus) { throw new Error('ExamCorrect utility could not detect user input status element!'); } @@ -130,6 +134,14 @@ export class ExamCorrect { partInput.disabled = deleteBox.checked; } + _inputKeypress() { + if (event.keyCode !== 13) { + return false; + } + + this._sendCorrectionHandler(); + } + _validateUserInput() { (!this._userInput.value) ? this._userInput.classList.add('no-value') : this._userInput.classList.remove('no-value');