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

survey-html-form: add autofocus parameter #1072

Merged
merged 2 commits into from Oct 2, 2020

Conversation

chrisbrickhouse
Copy link
Contributor

Users can provide the id of an element to focus on when the
slide is displayed. While HTML5 has an autofocus parameter
it is not universal and not all browsers support it. This
solution should work across browsers and is more in keeping
with the jsPsych object style.

Issue #1062

Users can provide the id of an element to focus on when the
slide is displayed. While HTML5 has an autofocus parameter
it is not universal and not all browsers support it. This
solution should work across browsers and is more in keeping
with the jsPsych object style.

Issue jspsych#1062
@becky-gilbert
Copy link
Collaborator

Thanks @chrisbrickhouse! I agree that the autofocus attribute isn't reliable and calling .focus() seems to work better. Thanks also for showing how this parameter works in the plugin's example file!

Somewhere around line 71 in the plugin, I think there needs to be a check that an element with the ID specified by trial.autofocus exists on the page, otherwise line 72 will produce an error. Perhaps there should be a console warning if no element with this ID is found. What do you think? If you agree, feel free to update the pull request or I can merge as is and then make changes.

When the autofocus parameter is set, check that
the specified element exists in the DOM and
check that the specified ID is unique. If there
is not exactly 1 element with the given ID, warn
the user about unexpected behavior.
@becky-gilbert
Copy link
Collaborator

Perfect, thanks very much!

@becky-gilbert becky-gilbert merged commit 402d4f0 into jspsych:master Oct 2, 2020
@becky-gilbert becky-gilbert mentioned this pull request Oct 2, 2020
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.

None yet

2 participants