Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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