From 666dac1c3bcef2357a4f706d6f095c929c7808ad Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Tue, 1 Oct 2024 10:12:07 +0100 Subject: [PATCH 1/9] New: Added support for _canShowCorrectness --- js/MatchingModel.js | 9 +++++++++ templates/matching.jsx | 14 +++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/js/MatchingModel.js b/js/MatchingModel.js index ac46613..0ab533d 100644 --- a/js/MatchingModel.js +++ b/js/MatchingModel.js @@ -27,6 +27,15 @@ export default class MatchingModel extends ItemsQuestionModel { options.push(...itemOptions); return options; }, []); + items.forEach(item => { + const itemOptions = (item._options || []); + item._correctAnswers = itemOptions + .filter(option => option._isCorrect) + .map(option => option.text || '') + .map(item => item.trim()) + .filter(Boolean) + .join(', '); + }); this.set({ _items: items, _selectable: items.length diff --git a/templates/matching.jsx b/templates/matching.jsx index 9db2b5a..1e829fc 100644 --- a/templates/matching.jsx +++ b/templates/matching.jsx @@ -8,6 +8,7 @@ export default function Matching(props) { _isInteractionComplete, _isCorrect, _shouldShowMarking, + _canShowCorrectness, _isCorrectAnswerShown, _items, _options, @@ -39,7 +40,8 @@ export default function Matching(props) { {_items.map(({ text, - _index + _index, + _correctAnswers }, index) => { const activeOption = _options.find(option => (option._itemIndex === _index) && option._isActive); const displayItemAsCorrect = (!_isEnabled && _shouldShowMarking && (_isCorrectAnswerShown || activeOption?._shouldBeSelected)); @@ -74,6 +76,16 @@ export default function Matching(props) { + {_canShowCorrectness && +
+
+ } + ); })} From 9122f6481ed7e98c6ac8b54ecab5db67b61c7622 Mon Sep 17 00:00:00 2001 From: kirsty-hames Date: Thu, 10 Oct 2024 14:53:56 +0100 Subject: [PATCH 2/9] example and readme updated --- README.md | 2 ++ example.json | 1 + 2 files changed, 3 insertions(+) diff --git a/README.md b/README.md index 42974a6..d42f43f 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ guide the learner’s interaction with the component. **\_canShowModelAnswer** (boolean): Setting this to `false` prevents the [**\_showCorrectAnswer** button](https://github.com/adaptlearning/adapt_framework/wiki/Core-Buttons) from being displayed. The default is `true`. +**\_canShowCorrectness** (boolean): Setting this to `true` replaces the associated `_canShowModelAnswer` toggle button and a comma separated list of correct options is displayed below the submitted item. The default is `false`. + **\_canShowFeedback** (boolean): Setting this to `false` disables feedback, so it is not shown to the user. The default is `true`. **\_canShowMarking** (boolean): Setting this to `false` prevents ticks and crosses being displayed on question completion. The default is `true`. diff --git a/example.json b/example.json index 1e181ca..0c4c8ee 100644 --- a/example.json +++ b/example.json @@ -17,6 +17,7 @@ "_isRandomQuestionOrder": false, "_questionWeight": 1, "_canShowModelAnswer": true, + "_canShowCorrectness": false, "_canShowFeedback": true, "_canShowMarking": true, "_recordInteraction": true, From b8a88b816655019e90f49d079fa08611fc18b421 Mon Sep 17 00:00:00 2001 From: kirsty-hames Date: Thu, 10 Oct 2024 14:58:43 +0100 Subject: [PATCH 3/9] schemas updated --- properties.schema | 9 +++++++++ schema/component.schema.json | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/properties.schema b/properties.schema index 1844d13..fd956d6 100644 --- a/properties.schema +++ b/properties.schema @@ -75,6 +75,15 @@ "validators": [], "help": "Allow the user to view the 'model answer' if they answer the question incorrectly?" }, + "_canShowCorrectness": { + "type": "boolean", + "required": false, + "default": false, + "title": "Display correct answers after submit", + "inputType": "Checkbox", + "validators": [], + "help": "If enabled, this replaces the associated 'model answer' toggle button and a comma separated list of correct options is displayed below the submitted question item." + }, "_canShowFeedback": { "type": "boolean", "required": true, diff --git a/schema/component.schema.json b/schema/component.schema.json index 03a5179..cbcaf3b 100644 --- a/schema/component.schema.json +++ b/schema/component.schema.json @@ -54,6 +54,12 @@ "description": "Allow the user to view the 'model answer' if they answer the question incorrectly. Defaults to true.", "default": true }, + "_canShowCorrectness": { + "type": "boolean", + "title": "Enable correct answers to display after submit", + "description": "If enabled, this replaces the associated 'model answer' toggle button and a comma separated list of correct options is displayed below the submitted question item", + "default": false + }, "_canShowFeedback": { "type": "boolean", "title": "Enable feedback", From bfddbebc2e690fa9560b909d9b5facc9bb291cff Mon Sep 17 00:00:00 2001 From: kirsty-hames Date: Thu, 10 Oct 2024 15:16:17 +0100 Subject: [PATCH 4/9] remove duplicate _canShowCorrectness condition --- templates/matching.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/matching.jsx b/templates/matching.jsx index 1e829fc..58f6e11 100644 --- a/templates/matching.jsx +++ b/templates/matching.jsx @@ -81,7 +81,7 @@ export default function Matching(props) { key={`answer-${_index}`} className="matching-item__answer-container" dangerouslySetInnerHTML={{ - __html: (_isInteractionComplete && _canShowCorrectness && _correctAnswers) || ' ' + __html: (_isInteractionComplete && _correctAnswers) || ' ' }}> } From f345265e4d1887c55e4fd53a6d4daba0fc53d147 Mon Sep 17 00:00:00 2001 From: kirsty-hames Date: Thu, 10 Oct 2024 16:14:48 +0100 Subject: [PATCH 5/9] default text prefix added for the list of correct options --- properties.schema | 9 +++++++++ schema/course.schema.json | 9 +++++++++ templates/matching.jsx | 4 +++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/properties.schema b/properties.schema index fd956d6..5491388 100644 --- a/properties.schema +++ b/properties.schema @@ -29,6 +29,15 @@ "validators": [], "help": "Text that will be announced by the screen reader when the learner selects the 'hide correct answer' button", "translatable": true + }, + "correctAnswerPrefix": { + "type": "string", + "required": false, + "default": "The correct answer is", + "inputType": "Text", + "validators": [], + "help": "If _canShowCorrectness is enabled, this text provides a prefix for the comma separated list of correct options displayed below the submitted question item", + "translatable": true } }, "properties": { diff --git a/schema/course.schema.json b/schema/course.schema.json index 00d6b54..5ce4190 100644 --- a/schema/course.schema.json +++ b/schema/course.schema.json @@ -28,6 +28,15 @@ "_adapt": { "translatable": true } + }, + "correctAnswerPrefix": { + "type": "string", + "title": "ARIA prefix for correct answer", + "description": "If _canShowCorrectness is enabled, this text provides a prefix for the comma separated list of correct options displayed below the submitted question item", + "default": "The correct answer is ", + "_adapt": { + "translatable": true + } } } } diff --git a/templates/matching.jsx b/templates/matching.jsx index 58f6e11..37db877 100644 --- a/templates/matching.jsx +++ b/templates/matching.jsx @@ -21,6 +21,8 @@ export default function Matching(props) { const displayAsCorrect = (_isInteractionComplete && (_isCorrectAnswerShown || _isCorrect)); + const correctAnswerPrefix = _globals?._components?._matching?.correctAnswerPrefix || ''; + return (
@@ -81,7 +83,7 @@ export default function Matching(props) { key={`answer-${_index}`} className="matching-item__answer-container" dangerouslySetInnerHTML={{ - __html: (_isInteractionComplete && _correctAnswers) || ' ' + __html: (_isInteractionComplete && correctAnswerPrefix + _correctAnswers) || ' ' }}>
} From ee8dd56508e09b13ae358fd5bc8de973adc63cff Mon Sep 17 00:00:00 2001 From: kirsty-hames Date: Mon, 14 Oct 2024 13:40:41 +0100 Subject: [PATCH 6/9] correctAnswersPrefix added to support both single and multiple correct answers --- js/MatchingModel.js | 3 +-- properties.schema | 9 +++++++++ schema/course.schema.json | 11 ++++++++++- templates/matching.jsx | 5 ++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/js/MatchingModel.js b/js/MatchingModel.js index 0ab533d..6a6e876 100644 --- a/js/MatchingModel.js +++ b/js/MatchingModel.js @@ -33,8 +33,7 @@ export default class MatchingModel extends ItemsQuestionModel { .filter(option => option._isCorrect) .map(option => option.text || '') .map(item => item.trim()) - .filter(Boolean) - .join(', '); + .filter(Boolean); }); this.set({ _items: items, diff --git a/properties.schema b/properties.schema index 5491388..8daf980 100644 --- a/properties.schema +++ b/properties.schema @@ -36,6 +36,15 @@ "default": "The correct answer is", "inputType": "Text", "validators": [], + "help": "If _canShowCorrectness is enabled, this text provides a prefix for the correct option displayed below the submitted question item", + "translatable": true + }, + "correctAnswersPrefix": { + "type": "string", + "required": false, + "default": "The correct answers are", + "inputType": "Text", + "validators": [], "help": "If _canShowCorrectness is enabled, this text provides a prefix for the comma separated list of correct options displayed below the submitted question item", "translatable": true } diff --git a/schema/course.schema.json b/schema/course.schema.json index 5ce4190..f1a88c9 100644 --- a/schema/course.schema.json +++ b/schema/course.schema.json @@ -32,8 +32,17 @@ "correctAnswerPrefix": { "type": "string", "title": "ARIA prefix for correct answer", + "description": "If _canShowCorrectness is enabled, this text provides a prefix for the correct option displayed below the submitted question item", + "default": "The correct answer is", + "_adapt": { + "translatable": true + } + }, + "correctAnswersPrefix": { + "type": "string", + "title": "ARIA prefix for correct answers", "description": "If _canShowCorrectness is enabled, this text provides a prefix for the comma separated list of correct options displayed below the submitted question item", - "default": "The correct answer is ", + "default": "The correct answers are", "_adapt": { "translatable": true } diff --git a/templates/matching.jsx b/templates/matching.jsx index 37db877..211b602 100644 --- a/templates/matching.jsx +++ b/templates/matching.jsx @@ -22,6 +22,7 @@ export default function Matching(props) { const displayAsCorrect = (_isInteractionComplete && (_isCorrectAnswerShown || _isCorrect)); const correctAnswerPrefix = _globals?._components?._matching?.correctAnswerPrefix || ''; + const correctAnswersPrefix = _globals?._components?._matching?.correctAnswersPrefix || ''; return (
@@ -47,6 +48,8 @@ export default function Matching(props) { }, index) => { const activeOption = _options.find(option => (option._itemIndex === _index) && option._isActive); const displayItemAsCorrect = (!_isEnabled && _shouldShowMarking && (_isCorrectAnswerShown || activeOption?._shouldBeSelected)); + const hasMultipleCorrectAnswers = _correctAnswers.length > 1; + return (
} From 30e805acfb8f2d2950d731eddc166cd3c99c2c9f Mon Sep 17 00:00:00 2001 From: kirsty-hames Date: Mon, 14 Oct 2024 13:55:54 +0100 Subject: [PATCH 7/9] correct answer prefix fix --- templates/matching.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/matching.jsx b/templates/matching.jsx index 211b602..4e65f23 100644 --- a/templates/matching.jsx +++ b/templates/matching.jsx @@ -86,7 +86,7 @@ export default function Matching(props) { key={`answer-${_index}`} className="matching-item__answer-container" dangerouslySetInnerHTML={{ - __html: (_isInteractionComplete && (hasMultipleCorrectAnswers ? correctAnswersPrefix.join(' ') : correctAnswerPrefix.join(' ')) + (hasMultipleCorrectAnswers ? _correctAnswers.join(', ') : _correctAnswers)) || ' ' + __html: (_isInteractionComplete && (hasMultipleCorrectAnswers ? (correctAnswersPrefix && correctAnswersPrefix + ' ') : (correctAnswerPrefix && correctAnswerPrefix + ' ')) + (hasMultipleCorrectAnswers ? _correctAnswers.join(', ') : _correctAnswers)) || ' ' }}>
} From 7a50fa3dff089f0cff68ee92339db80c8babcde3 Mon Sep 17 00:00:00 2001 From: kirsty-hames Date: Mon, 14 Oct 2024 14:46:49 +0100 Subject: [PATCH 8/9] remove unnecessary answer prefix condition --- templates/matching.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/matching.jsx b/templates/matching.jsx index 4e65f23..6da3105 100644 --- a/templates/matching.jsx +++ b/templates/matching.jsx @@ -21,8 +21,8 @@ export default function Matching(props) { const displayAsCorrect = (_isInteractionComplete && (_isCorrectAnswerShown || _isCorrect)); - const correctAnswerPrefix = _globals?._components?._matching?.correctAnswerPrefix || ''; - const correctAnswersPrefix = _globals?._components?._matching?.correctAnswersPrefix || ''; + const correctAnswerPrefix = _globals?._components?._matching?.correctAnswerPrefix + ' ' || ''; + const correctAnswersPrefix = _globals?._components?._matching?.correctAnswersPrefix + ' ' || ''; return (
@@ -86,7 +86,7 @@ export default function Matching(props) { key={`answer-${_index}`} className="matching-item__answer-container" dangerouslySetInnerHTML={{ - __html: (_isInteractionComplete && (hasMultipleCorrectAnswers ? (correctAnswersPrefix && correctAnswersPrefix + ' ') : (correctAnswerPrefix && correctAnswerPrefix + ' ')) + (hasMultipleCorrectAnswers ? _correctAnswers.join(', ') : _correctAnswers)) || ' ' + __html: (_isInteractionComplete && (hasMultipleCorrectAnswers ? correctAnswersPrefix : correctAnswerPrefix) + (hasMultipleCorrectAnswers ? _correctAnswers.join(', ') : _correctAnswers)) || ' ' }}>
} From 998aa08ad3bb0e150f316c081de6a720c7b41ede Mon Sep 17 00:00:00 2001 From: kirsty-hames Date: Tue, 5 Nov 2024 13:06:43 +0000 Subject: [PATCH 9/9] simplify _correctAnswers --- templates/matching.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/matching.jsx b/templates/matching.jsx index 6da3105..87a07af 100644 --- a/templates/matching.jsx +++ b/templates/matching.jsx @@ -86,7 +86,7 @@ export default function Matching(props) { key={`answer-${_index}`} className="matching-item__answer-container" dangerouslySetInnerHTML={{ - __html: (_isInteractionComplete && (hasMultipleCorrectAnswers ? correctAnswersPrefix : correctAnswerPrefix) + (hasMultipleCorrectAnswers ? _correctAnswers.join(', ') : _correctAnswers)) || ' ' + __html: (_isInteractionComplete && (hasMultipleCorrectAnswers ? correctAnswersPrefix : correctAnswerPrefix) + _correctAnswers.join(', ')) || ' ' }}> }