Error: Backspace exiting experiment prematurely

URL of experiment:

Description of the problem:

Some participants reported being booted from the experiment after pressing the backspace during a text input portion. Everyone has reported using the Firefox browser. However, I have not been able to replicate this experience on my own, so I don’t know if there is a specific error message that accompanies the premature experiment closure. Has anyone else dealt with this issue? Any help would be greatly appreciated!

Is there an error caused by trying to delete something from an empty string? You could force backspace to only work if the current response has at least one letter.

Thank you for the lightning fast reply!

I am not sure what exactly is causing the error. I tried the backspace without any letters in the response. Nothing happened. The experiment continued just fine. If this is an occasional issue, I would like to add it in in case this affects some people!

Here is the code under Each Frame in the routine that asks for a text response:

let theseKeys = psychoJS.eventManager.getKeys();
if (theseKeys.length > 0) { // at least one key was pressed
textAdd = theseKeys[theseKeys.length-1];
}

if (textAdd === ‘return’) {
textAdd = ‘’; // Add nothing
continueRoutine = false; // End routine (if that is what you want)
} else if (textAdd === ‘space’) {
textAdd = ’ '; // Add a space
} else if (textAdd === ‘backspace’) {
text_20.text = text_20.text.slice(0, -1);
textAdd = undefined;
} else if ([‘lshift’, ‘rshift’].includes(textAdd)) {
modify = true;
} else if (textAdd !== undefined) {
if (modify) {
text_20.text = text_20.text + textAdd.toUpperCase();
modify = false;
} else {
text_20.text = text_20.text + textAdd
}
textAdd = undefined;
}

How would I add code to force backspace into working only if there is at least one letter?

Thanks again so much for the help!

Try moving the } from the fourth line of your code to the bottom. You only need to check textAdd if there’s a key press.

Great! That includes everything in the first if statement. Thank you very much