Editable Textbox no autofocus online

URL of experiment: Eva Specht / TextBox no autofocus online · GitLab

Description of the problem:

In my experiment I use the editable TexBox (Beta) component to collect answers.

Offline, the text box gets auto-focus so that the test subjects don’t have to keep manually clicking in the box before typing in the answer.

Online, however, the text box does not get auto-focus. In each trial, the box must be manually clicked with the mouse before the answer can be typed and ‘Enter’ can be pressed to move on to the next trial.

Is this a bug in PsychoJS and does anyone have a solution to this problem?

I am using Builder, PsychoPy v2020.2.10 on macOS Catalina 10.15.7.

Thanks for helping!

1 Like

Hi there,

You need the following line of code in a JS code component in the each frame tab to bring the textbox to focus online:

textbox_name._pixi.focus()

Hope this helps,

Becca

Ps. We are looking to make the behaviour of the textbox online equivalent to the local textbox in this regard! :blush:

2 Likes

Had the same error, this fixed it for me. Thank you, Becca!

Thanks, Becca, that solved the issue!

Happy to help! I hope you don’t mind I marked the solution here for future users :slight_smile:

All the best!

Becca

Hi @Becca.

I am facing the same problem and tried applying this solution as shown below.

But unfortunately, once uploaded to Pavlovia and run, when the experiment got that point it threw this error.

Is there anything else I have to do to make this work - like include some special library or something? Is that term _pixi part of the standard Python tools?

Thanks for any help - I really need to get this working. :frowning:

D.

Hi Dan - I think now you should just be able to add a code component with this in the “begin routine” tab textbox.refresh() hope that helps

WOOOHOOOOO!!!

IT WORKS!!!

(apologies for the caps - but this problem has been kicking my butt for AGES now…)

YAY!

Some more details - I figured out that the error I saw above was caused by my code being higher up in the list than the Textbox to which it referred. Also - I had to remove all the attempts at the _pixi approach for the ‘textbox.refresh’ thingo to work. BUT…

It now does.

Thank you SO MUCH @Becca and @wakecarter.

Very happy right now.

D.

1 Like

Oh. No. Wait.

This approach works on-line. But… when I try and run it locally now - PyschoPy throws an error.

Sigh…

Is this expected? Any ideas?

(Error message in the Runner window above)

D.

What if you change that code component to Both and then delete the Python side?

Ah. Yes. And THIS seems to work.

And that’s an elegant little solution to an ugly problem. :slight_smile:

Also has made more cognisant of what the two panels of the code window can be used for.

Thanks.

:slight_smile:

D.

Hi,
I am trying to do something similar in javascript but I can’t find the right information.
I would like to show 5 textboxes at once. In each it is written “type here”. As soon the mouse hits the textbox, “type here” will disappear to have only the cursor available. I was able to make it in python but I am struggling to find the right function to do so in JavaScript.