Disabling a key in TextInput element

PennController for IBEX Forums Support Disabling a key in TextInput element

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #7814
    marisolmuru
    Participant

    Hi Jeremy!

    I’m trying to disable a particular key in the Text Input element. Here you gave me a javascript function, but I haven’t been able to implement it in my script (https://farm.pcibex.net/r/QfspMA/). I’ve tried stating the function at the beginning of the script and then using the .call() command in the NewTrial or creating and executing the function inside the trial, but none seem to work.

    I leave the javascript function here:

    newTextInput("myInput", "").print()
    ,
    newFunction(()=>setTimeout(()=>document.querySelector("textarea.PennController-myInput").addEventListener("keydown",e=>{
        if (!e.key.match(/s/i)) return true;
        e.preventDefault();
        e.stopPropagation();
        return false;
    }),200)).call()

    Thanks in advance!
    M.

    #7815
    Jeremy
    Keymaster

    Hi Marisol,

    You name the TextInput element in your project "PA", so you need to replace "textarea.PennController-myInput" with "textarea.PennController-PA". Also, your code is currently not using call on the Function element, so its content won’t be executed: you need to add back .call() for it to work. Then any keypress on S will fail to add that character in the input box

    Jeremy

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.