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 2 commits into
base: main
Choose a base branch
from

Conversation

crava2199
Copy link

In case of multiple forms in page, document.querySelector("form") won't find the proper one.
I've added a trial_form_id to select the form injected from the plugin and add the submit event listener to it.

Copy link

changeset-bot bot commented Nov 21, 2024

🦋 Changeset detected

Latest commit: afe9ebc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@jspsych/plugin-survey-multi-choice Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Collaborator

@jadeddelta jadeddelta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey, thanks for the catch @crava2199! just left a bit of a comment down, and also don't forget: for any modifications to plugin code, be sure to run npm run changeset to add a changeset to the PR, just helps us with versioning :)

@@ -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) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it would just be more simple to instead directly use querySelector on display_element, which represents the container of the current experiment. just saves the hassle of using interpolation so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants