Getting the value of the selected choice in a dropdown menu

PennController for IBEX Forums Support Getting the value of the selected choice in a dropdown menu

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #5221
    doroahn
    Participant

    Hi Jeremy,

    I am wondering how I can set a variable to the value of the selected choice in a dropdown menu, and was not able to find answers to this in the documentations or this forum. So sorry if this is already discussed somewhere.

    Basically I am wondering if there is a dropdown menu version of getTextInput.
    I am able to log the selection but I wasn’t able to find a way to call for that value.
    Is there a command that’s available for this? Thank you!

    #5224
    Jeremy
    Keymaster

    Hi,

    This is a bug (or at least unintended behavior), I miscoded the values of DropDown elements. I’ll fix the issue in the next release, but in the meantime you can upload a file that you name valueDropDown.js in your Controllers folder with the following content:

    (()=>{
    let override = function(fn, ...args) {
        let r = fn.call(this, ...args), e = r._element;
        Object.defineProperty(e,'text',{get(){ 
            let s = e.selections;
            if (s instanceof Array && s.length>0) return s[s.length-1][1];
            else return "";
        }});
        return r;
    };
    let oldndd = PennController.Elements.newDropDown, oldgdd = PennController.Elements.getDropDown;
    PennController.Elements.newDropDown = function(...args){ return override.call(this, oldndd, ...args); }
    PennController.Elements.getDropDown = function(...args){ return override.call(this, oldgdd, ...args); }
    })();

    Then you can use the DropDown element as you would a TextInput element, eg:

    newTrial(
        newDropDown("test", "")
            .add( "waf" , "woof" )
            .print()
            .wait()
        ,
        newVar("select").global().set( getDropDown("test") )
        ,
        newText("").text( getVar("select") ).print()
        ,
        newButton("next").print().wait()
    )

    Jeremy

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