Skip to content

Commit

Permalink
Merge pull request #93 from makmentins/JI-5501-clear-previous-state-o…
Browse files Browse the repository at this point in the history
…n-resettask

JI-5501 Always clear previousState in resetTask,
  • Loading branch information
otacke authored Mar 7, 2024
2 parents 5f131c4 + a4719bd commit cdea29b
Showing 1 changed file with 34 additions and 21 deletions.
55 changes: 34 additions & 21 deletions scripts/essay.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,28 +418,33 @@ H5P.Essay = function ($, Question) {
* @see contract at {@link https://h5p.org/documentation/developers/contracts#guides-header-5}
*/
Essay.prototype.resetTask = function (params) {
params = params || {};
this.setViewState('task');

this.setExplanation();
this.removeFeedback();
this.hideSolution();

this.hideButton('show-solution');
this.hideButton('try-again');

// QuestionSet can control check button despite not in Question Type contract
if (this.params.behaviour.enableCheckButton) {
this.showButton('check-answer');
}
// Always reset previousState
this.previousState = {};
this.isAnswered = false;

if (!params.skipClear) {
this.inputField.setText('');
// Reset DOM only if it has been loaded
if (this.isContentInitialized()) {
params = params || {};
this.setViewState('task');

this.setExplanation();
this.removeFeedback();
this.hideSolution();

this.hideButton('show-solution');
this.hideButton('try-again');

// QuestionSet can control check button despite not in Question Type contract
if (this.params.behaviour.enableCheckButton) {
this.showButton('check-answer');
}

if (!params.skipClear) {
this.inputField.setText('');
}
this.inputField.enable();
this.inputField.focus();
}
this.inputField.enable();
this.inputField.focus();

this.isAnswered = false;
};

/**
Expand Down Expand Up @@ -1071,7 +1076,7 @@ H5P.Essay = function ($, Question) {
* to show up that restart button without the need to.
*/
if (!inputFieldText) {
return;
return {};
}

return {
Expand All @@ -1092,6 +1097,14 @@ H5P.Essay = function ($, Question) {
this.viewState = state;
};

/**
* Checks if the content has been initialized or loaded into the DOM.
* @returns {boolean} True if the content has been initialized, false otherwise.
*/
Essay.prototype.isContentInitialized = function() {
return !!this.inputField; // Check if inputField exists
};

/** @constant {string}
* latin special chars: \u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF
* greek chars: \u0370-\u03FF
Expand Down

0 comments on commit cdea29b

Please sign in to comment.