Skip to content
Snippets Groups Projects
Commit 25d029a8 authored by Eliott Sammier's avatar Eliott Sammier
Browse files

Fix Clear button not working with custom question

parent 76d38242
No related branches found
No related tags found
No related merge requests found
...@@ -51,11 +51,25 @@ export const gapfillSelectWidget = { ...@@ -51,11 +51,25 @@ export const gapfillSelectWidget = {
optionElem.innerText = opt; optionElem.innerText = opt;
segmentElem.appendChild(optionElem); segmentElem.appendChild(optionElem);
} }
// Add listener to update the question's value when the selector's value changes // Add callback to update the question's value when the selector's value changes
segmentElem.addEventListener("change", (e) => { segmentElem.addEventListener("change", (e) => {
// The select node knows its index, therefore is able to update the question value at the correct index // The select node knows its index, therefore is able to update the question value at the correct index
question.value[parseInt(e.target.getAttribute("data-index"))] = e.target.value; question.value[parseInt(e.target.getAttribute("data-index"))] = e.target.value;
}); });
// Add callback to update the DOM nodes when the question's value changes
question.valueChangedCallback = () => {
const gaps = question.wrapperElement.querySelectorAll("#gapfill-container select");
if (question.value instanceof Array && question.value.length === gaps.length) {
for (const i in question.value) {
gaps[i].value = question.value[i];
}
} else {
// Unknown value -> reset all fields
for (const gap of gaps) {
gap.value = undefined;
}
}
}
nbGaps++; nbGaps++;
} }
// Add segment // Add segment
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment