Skip to content

Commit

Permalink
Fix: Marking ticks and mixed configs (fixes #148) (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfoster authored Sep 30, 2024
1 parent d7a9385 commit a8bd4a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions js/textInputModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion templates/textinput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>

<div
className={classes([
Expand Down

0 comments on commit a8bd4a1

Please sign in to comment.