diff --git a/src/scripts/h5p-crossword-content.js b/src/scripts/h5p-crossword-content.js index c3641f1..d3c9a0d 100644 --- a/src/scripts/h5p-crossword-content.js +++ b/src/scripts/h5p-crossword-content.js @@ -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. */ @@ -291,7 +299,7 @@ export default class CrosswordContent { this.answerGiven = true; - if (this.table.isFilled()) { + if (this.isTableFilled()) { this.callbacks.onTableFilled(); } } diff --git a/src/scripts/h5p-crossword.js b/src/scripts/h5p-crossword.js index cc43d10..5688416 100644 --- a/src/scripts/h5p-crossword.js +++ b/src/scripts/h5p-crossword.js @@ -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(() => { @@ -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');