feat(frontend): Vue can now interact with the chosen answers for questions.
This commit is contained in:
parent
6d452c7f72
commit
63d1ed8bd2
6 changed files with 99 additions and 1 deletions
|
@ -0,0 +1,26 @@
|
|||
export const multipleChoiceQuestionAdapter: GiftAdapter = {
|
||||
questionType: "MC",
|
||||
|
||||
installListener(questionElement: Element, answerUpdateCallback: (newAnswer: string | number | object) => void): void {
|
||||
questionElement.querySelectorAll('input[type=radio]').forEach(element => {
|
||||
const input = element as HTMLInputElement;
|
||||
|
||||
input.addEventListener('change', () => {
|
||||
answerUpdateCallback(parseInt(input.value));
|
||||
});
|
||||
// Optional: initialize value if already selected
|
||||
if (input.checked) {
|
||||
answerUpdateCallback(parseInt(input.value));
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setAnswer(questionElement: Element, answer: string | number | object): void {
|
||||
questionElement.querySelectorAll('input[type=radio]').forEach(element => {
|
||||
const input = element as HTMLInputElement;
|
||||
console.log(`input: ${input.value}, answer: ${answer}`);
|
||||
input.checked = String(answer) === String(input.value);
|
||||
console.log(input.checked);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue