Reply To: 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 Reply To: Getting the value of the selected choice in a dropdown menu

#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