Skip to content

Commit

Permalink
Fix restoring previous state with instant feedback enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
otacke committed Jan 24, 2021
1 parent 5ee5546 commit 324e273
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/scripts/h5p-crossword-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,14 @@ export default class CrosswordContent {
}
}

/**
* Check whether all relevant cells have been filled.
* @return {boolean} True, if all relevant cells have been filled, else false.
*/
isTableFilled() {
return this.table.isFilled();
}

/**
* Show solution.
*/
Expand Down Expand Up @@ -291,7 +299,7 @@ export default class CrosswordContent {

this.answerGiven = true;

if (this.table.isFilled()) {
if (this.isTableFilled()) {
this.callbacks.onTableFilled();
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/scripts/h5p-crossword.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ export default class Crossword extends H5P.Question {
// Register content with H5P.Question
this.setContent(this.content.getDOM());

// Previous state might have been a filled table
if (this.params.behaviour.enableInstantFeedback && this.content.isTableFilled()) {
this.checkAnswer();
}

// Content may need a resize once it's displayed (media queries or pseudo elements)
Util.waitForDOM('.h5p-crossword-input-container', () => {
setTimeout(() => {
Expand Down Expand Up @@ -197,6 +202,10 @@ export default class Crossword extends H5P.Question {
* Check answer.
*/
this.checkAnswer = () => {
if (!this.content) {
return; // Call by previous state, not ready yet
}

this.content.checkAnswer();

this.hideButton('check-answer');
Expand Down

0 comments on commit 324e273

Please sign in to comment.