feat(exam-correct): submit on enter

This commit is contained in:
Gregor Kleen 2020-02-07 21:17:29 +01:00
parent 23044b28db
commit 10de1a7de7

View File

@ -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');