diff --git a/js/textInputModel.js b/js/textInputModel.js index 18c7dc0..9be2aa8 100644 --- a/js/textInputModel.js +++ b/js/textInputModel.js @@ -89,11 +89,8 @@ class TextInputModel extends QuestionModel { } isCorrect() { - if (this.get('_answers')) { - this.markGenericAnswers(); - } else { - this.markSpecificAnswers(); - } + this.markGenericAnswers(); + this.markSpecificAnswers(); return this.get('_items').every(({ _isCorrect }) => _isCorrect); } @@ -109,6 +106,8 @@ class TextInputModel extends QuestionModel { const usedAnswerIndexes = []; this.get('_items').forEach(item => { + const hasItemAnswers = Boolean(item._answers?.length); + if (hasItemAnswers) return; correctAnswers.forEach((answerGroup, answerIndex) => { if (usedAnswerIndexes.includes(answerIndex)) return; @@ -133,8 +132,9 @@ class TextInputModel extends QuestionModel { markSpecificAnswers() { let numberOfCorrectAnswers = 0; this.get('_items').forEach(item => { + const hasItemAnswers = Boolean(item._answers?.length); + if (!hasItemAnswers) return; const answers = item._answers; - if (!answers) return; const userAnswer = item.userAnswer || ''; const isCorrect = this.checkAnswerIsCorrect(answers, userAnswer); item._isCorrect = isCorrect; diff --git a/templates/textinput.jsx b/templates/textinput.jsx index 469eab8..1337f6a 100644 --- a/templates/textinput.jsx +++ b/templates/textinput.jsx @@ -33,7 +33,7 @@ export default function TextInput (props) { role='group' > - {props._items.map(({ prefix, _index, input, placeholder, userAnswer, suffix }, index) => + {props._items.map(({ prefix, _index, input, placeholder, userAnswer, suffix, _isCorrect }, index) =>