Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MACAO Hugo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Beniamine
MACAO Hugo
Commits
c09287a1
Commit
c09287a1
authored
Jun 14, 2024
by
Eliott Sammier
Browse files
Options
Downloads
Patches
Plain Diff
Add answer checking to gap-fill question type
parent
ba689d08
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
macao/assets/quiz.js
+17
-6
17 additions, 6 deletions
macao/assets/quiz.js
macao/content/activities/20/quiz.json
+6
-0
6 additions, 0 deletions
macao/content/activities/20/quiz.json
with
23 additions
and
6 deletions
macao/assets/quiz.js
+
17
−
6
View file @
c09287a1
...
...
@@ -22,33 +22,44 @@ let gapfillSelectWidget = {
Survey
.
Serializer
.
addClass
(
this
.
name
,
[],
null
,
"
empty
"
);
},
/** Static HTML template rendered by SurveyJS */
htmlTemplate
:
'
<p id="gapfill-container"><template id="template-select"><select class="my-custom-class"><option selected/></select></template></p>
'
,
//Our element will be rendered base on template.
//We do not need to do anything here
htmlTemplate
:
'
<p id="gapfill-container"><template id="template-select"><select class="my-custom-class"><option selected/></select></template></p>
'
,
/**
* Function called after the HTML template is rendered. This time we actually have the `question` object
* and the `el` element, to build the question according to the JSON
*/
afterRender
:
function
(
question
,
el
)
{
// The gap-fill text is made of segments, which are either plain pieces
// of text (strings) or "gaps" with a few options to select (string arrays).
// We append these to build the text, turning strings into <span>s and
// gaps into <select>s
let
nbGaps
=
0
;
for
(
segment
of
question
.
jsonObj
.
segments
)
{
if
(
typeof
segment
===
'
string
'
||
segment
instanceof
String
)
{
segmentElem
=
document
.
createElement
(
"
span
"
);
segmentElem
.
innerText
=
segment
;
}
else
if
(
segment
instanceof
Array
)
{
// Get the <select> element
// It's a gap
// Create the <select> element
segmentElem
=
document
.
getElementById
(
"
template-select
"
).
content
.
firstChild
.
cloneNode
(
true
);
segmentElem
.
setAttribute
(
"
data-index
"
,
nbGaps
);
// The node knows its index
// Create and append options
for
(
opt
of
segment
)
{
optionElem
=
document
.
createElement
(
"
option
"
);
optionElem
.
innerText
=
opt
;
segmentElem
.
appendChild
(
optionElem
);
}
// Add listener to update the question's value when the selector's value changes
segmentElem
.
addEventListener
(
"
change
"
,
(
e
)
=>
{
// The select node knows its index, therefore is able to update the question value at the correct index
this
.
question
.
value
[
parseInt
(
e
.
target
.
getAttribute
(
"
data-index
"
))]
=
e
.
target
.
value
;
});
nbGaps
++
;
}
// Add segment
el
.
appendChild
(
segmentElem
);
}
}
question
.
value
=
new
Array
(
nbGaps
);
},
};
...
...
This diff is collapsed.
Click to expand it.
macao/content/activities/20/quiz.json
+
6
−
0
View file @
c09287a1
...
...
@@ -30,6 +30,12 @@
"for the"
],
" winter-time'."
],
"correctAnswer"
:
[
"my mother"
,
"the apples"
,
"the tree"
,
"for the"
]
}
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment