Editable TextBox: Continues to appear on subsequent routine (doesn't end in current Routine)

v2020.2.3

I’m trying to add an editable text box to get free response from participants. This works fine in Builder for the Routine that has the text box, in that you can edit the text box, proceed to the next routine, and the text typed is saved in the data file.

However in the following routine, while the text box doesn’t appear at the start, it does appear if you mouse click in the location of where the prior text box was, and if you hold down the mouse in that location you can continue to edit the text (and the prior input text carries over). If you click outside of the location of the prior text box, it doesn’t appear.
If the text box is not editable, this doesn’t occur (as expected).

I’m guessing it’s carrying over mouse clicks/keys validity within the textBox coordinates instead of ending them when the routine ends. I tried adding “TextBox.setAutoDraw(False)” to End Routine, but the behavior continues as described above. I compiled to code to see if I could figure out another solution but haven’t been able to figure it out.

So far I’ve only tried this in Builder, but plan to get it working on Pavlovia.

Attached psyexp. Any suggestions? I know there are ways to create an editable text box fully in code components, but I’d rather use textBox (& force-end using code comp if need be)!

textBox.psyexp (11.5 KB)

Aha, I think I see what’s going on! Thanks for spotting this.

Essentially, autoDraw adds the component to a list of components to automatically draw each frame, whilst being editable (a parameter which is currently only applicable to Textbox components) adds it to a different list of editable objects to check for clicks on. So removing it from autoDraw does prevent it from being drawn when not selected, however selecting it still results in a draw command.

Fixing this quickly will require you to change a protected attribute, which is usually not advisable, but I think in this case it’s the best way:

for c in win._editableChildren:
    if c() == TextBox:
        win._editableChildren.remove(c)

I’ll push a fix now which essentially executes this code when autoDraw is set to false

Thanks @TParsons! Adding:

for c in win._editableChildren:
    if c() == TextBox:
        win._editableChildren.remove(c)

to py End Routine makes it so that we don’t see the text box in the following routine, no matter where we click. This behavior was specific to Builder, and no fix is needed for Pavlovia.

Does this mean that after the next BugFix push, I should change that code chunk to:

TextBox.setAutoDraw(False)

so that the same behavior is executed, or will there be no need for it?

Also, thank you for explaining what’s going on! It makes it easier for us to debug other problems when we know what’s happening under the hood

No problem, glad I could help! Once the next bug fix release is out, you will be able to replace that code with TextBox.setAutoDraw(False), but it will still work either way! The key is the if statement - once the bug fix release is out, the object will already have been removed by the time that code is reached, so that if statement will be False and the code within it will not be executed.

1 Like

HI Tparsons, I am having this issue as well. I am still new to psychopy and I am not sure where to add the code to fix the issue. Thank you!

MDS16IMTDMTV1.py (22.6 KB)

It looks like you already have setAutoDraw(False) at the bottom of the Routine loop, so once you update to 2020.2.5 it should work. Please let me know if it doesn’t!

1 Like

Unfortunately it still is showing up when holding click. I have 2020.2.5 installed and am using that version. I have tried adding

Also, I am sorry to bring this up here, but I am really stuck on this issue and it’s been two days with no responses on my post. When I use the slider response, putting in labels causes an unspecified java error. I have tried everything I know but I am just not sure how to fix this and it’s causing me a lot of stress. This is the restarted project, I haven’t been able to continue due to the boxes appearing again and the slider crashing online. V10.psyexp (16.9 KB)

Investigating this has lead me down a bit of a rabbit hole - I’ve (tentatively…) fixed the bug, but it required a lot of changes so this fix may not appear in the standalone install until the next major release (2020.3.0 or 2021.0.0, depending on release date). If you can run PsychoPy directly from Python via something like PyCharm, or even from the command window, then you can pull down the branch from GitHub and it should work! Here’s the pull request:

But if you would rather stick with standalone PsychoPy, then as a temporary fix you could set the position of the textbox to be somewhere offscreen and then use a Code component to move it on screen when needed (by setting textbox.pos). It’s certainly not the cleanest solution, but short of getting all up in the guts of the code like I just did I can’t think how else to get the desired behaviour!

Can you spell out the temporary solution for standalone PsychoPy you suggest here? Sorry, psychopy newbie. Thanks!

If the units for your textbox are height, you can set the position of the textbox to be (0, 2) and it will then be well off the screen - as it will be 2x the height of the screen away from the middle. Then you can make a Code component and put in the Begin Routine tab something like:

myTextbox.pos = (x,y)

with myTextbox being the name of your textbox and (x,y) being the position you want it to be in

Thanks for your response - it seems to be working now without this, though I’ll keep it as a backup option.