Skip to content

Commit

Permalink
added form id in querySelector to plugin-survey-multi-choice
Browse files Browse the repository at this point in the history
  • Loading branch information
crava2199 committed Nov 21, 2024
1 parent bd3ed55 commit df65ce0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/plugin-survey-multi-choice/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ type Info = typeof info;
class SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {
static info = info;

constructor(private jsPsych: JsPsych) {}
constructor(private jsPsych: JsPsych) { }

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 = "";

Expand All @@ -148,9 +150,9 @@ class SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {

// form element
if (trial.autocomplete) {
html += '<form id="jspsych-survey-multi-choice-form">';
html += `<form id="${trial_form_id}">`;
} 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
// so that the data are always associated with the same question regardless of order
Expand Down Expand Up @@ -233,7 +235,7 @@ class SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {
// render
display_element.innerHTML = html;

document.querySelector("form").addEventListener("submit", (event) => {
document.querySelector(`form#${trial_form_id}`).addEventListener("submit", (event) => {
event.preventDefault();
// measure response time
var endTime = performance.now();
Expand Down

0 comments on commit df65ce0

Please sign in to comment.