added form id in querySelector to plugin-survey-multi-choice

This commit is contained in:
crava2199 2024-11-21 10:12:22 +01:00
parent bd3ed55239
commit df65ce0967

View File

@ -123,7 +123,9 @@ class SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {
constructor(private jsPsych: JsPsych) { } constructor(private jsPsych: JsPsych) { }
trial(display_element: HTMLElement, trial: TrialType<Info>) { trial(display_element: HTMLElement, trial: TrialType<Info>) {
var plugin_id_name = "jspsych-survey-multi-choice";
const plugin_id_name = "jspsych-survey-multi-choice";
const trial_form_id = `${plugin_id_name}_form`;
var html = ""; var html = "";
@ -148,9 +150,9 @@ class SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {
// form element // form element
if (trial.autocomplete) { if (trial.autocomplete) {
html += '<form id="jspsych-survey-multi-choice-form">'; html += `<form id="${trial_form_id}">`;
} else { } else {
html += '<form id="jspsych-survey-multi-choice-form" autocomplete="off">'; html += `<form id="${trial_form_id}" autocomplete="off">`;
} }
// generate question order. this is randomized here as opposed to randomizing the order of trial.questions // generate question order. this is randomized here as opposed to randomizing the order of trial.questions
// so that the data are always associated with the same question regardless of order // so that the data are always associated with the same question regardless of order
@ -233,7 +235,7 @@ class SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {
// render // render
display_element.innerHTML = html; display_element.innerHTML = html;
document.querySelector("form").addEventListener("submit", (event) => { document.querySelector(`form#${trial_form_id}`).addEventListener("submit", (event) => {
event.preventDefault(); event.preventDefault();
// measure response time // measure response time
var endTime = performance.now(); var endTime = performance.now();