Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Added support for _canShowCorrectness #197

Merged
merged 9 commits into from
Nov 5, 2024
9 changes: 9 additions & 0 deletions js/MatchingModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion templates/matching.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default function Matching(props) {
_isInteractionComplete,
_isCorrect,
_shouldShowMarking,
_canShowCorrectness,
_isCorrectAnswerShown,
_items,
_options,
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -74,6 +76,16 @@ export default function Matching(props) {

</div>

{_canShowCorrectness &&
<div
key={`answer-${_index}`}
className="matching-item__answer-container"
dangerouslySetInnerHTML={{
__html: (_isInteractionComplete && _canShowCorrectness && _correctAnswers) || '&nbsp;'
cahirodoherty-learningpool marked this conversation as resolved.
Show resolved Hide resolved
}}>
</div>
}

</div>
);
})}
Expand Down
Loading