DropDown
element
description
Represents a drop-down list.
syntax
newDropDown(ELEMENT_NAME: string, DEFAULT_TEXT: string)
-
ELEMENT_NAME
: The name of the newly-created element. -
DEFAULT_TEXT
: represents default text displayed
note(s)
since
PennController 1.2example(s)
+ By default, a **DropDown** element does not have any options. To add options, use the command `dropdown.add`. + The"DEFAULT_TEXT"
string parameter does not create a drop-down list option.
newTrial("option-1",
newText("like", "I like ")
,
newDropDown("fruits", "(select a fruit)")
.add("apples", "bananas", "oranges")
.before(getText("like"))
.print()
)
newTrial("option-2",
newDropDown("fruits", "(select a fruit)")
.add("apples", "bananas", "oranges")
,
newText("like", "I like ")
.after(getDropDown("fruits"))
.print()
)
Action commands
dropdown.add
syntax
.add()
description
Adds an option, or several options to the drop-down list.
example
click to expand
@newDropDown("language" , "First language")
$ .add( "English" , "French" , "Tagalog" )
@ .print()
- Creates a drop-down list with default text First language and adds three options to it: English, French and Tagalog, then prints the list onto the page.
dropdown.callback
syntax
.callback()
description
Will execute the command(s) whenever an option is selected from the drop-down list.
example
click to expand
@newText("The weather is")
@ .after( newDropDown("temp","...").add("cold","warm","hot") )
@ .after( newText("implicature", "implies that the weather is ...") )
@ .print()
@,
@getDropDown("temp")
@$ .callback(
$ getDropDown("temp")
$ .test.selected("warm").success(
$ getText("implicature").text("implicates that the weather is not hot")
$ )
$ .test.selected("hot").success(
$ getText("implicature").text("implies that the weather is not cold")
$ )
$ .test.selected("cold").success(
$ getText("implicature").text("implies that the weather is not even warm")
$ )
@ )
- Prints The weather is … implies that the weather is … onto the page, where the first occurrence of … is a drop-down list containing the options cold, warm and hot. Upon selection of the option, the continuation will be modified accordingly to the selected option.
dropdown.log
syntax
.log()
description
Will add a line to the results file for the current trial reporting what option was selected.
example
click to expand
@newDropDown("language" , "First language")
@ .add( "English" , "French" , "Tagalog" )
@ .print()
@ .log()
- Adds a line for the value selected from the dropdown at the end of the trial.
dropdown.once
syntax
.once()
description
Will disable the DropDown element after selection occurs.
example
click to expand
@newText("I saw Erika talk to Nate.")
$ .after( newDropDown("").add("He","She").once() )
@ .after( newText("seemed anxious.") )
@ .print()
- Prints I saw Erika talk to Nate. _ seemed nervous* onto the page, where *_ is a drop-down list containing the options He and She. The command
.once
makes the selection of He or She definitive.
dropdown.remove
syntax
.remove()
description
Removes a single option from the list. Nothing happens if the option passed as an argument is in fact not in the list.
example
click to expand
@newDropDown("value" , "Truth value")
@ .add( "True" , "False" )
@ .print()
@,
@newScale("logic", "Binary","Three-valued")
@ .default("Binary")
@ .before( newText("Logic: ") )
@ .labelsPosition("right")
@ .callback(
@ getScale("logic")
@ .test.selected("Three-valued")
@ .success(
@ getDropDown("value")
@ .add("Other")
@ )
@ .failure(
@ getDropDown("value")
$ .remove("Other")
@ )
@ )
@ .print()
- Creates a drop-down list with two options, True and False, and prints it onto the page. Then creates a Scale element with two options, Binary and Three-value, the former being selected by default, preceded with the text Logic:. Whenever a value gets selected on the Scale, a test checks whether the selected value corresponds to Three-valued and, if so, it adds the option Other to the drop-down list, or removes it from the list otherwise.
dropdown.select
syntax
.select()
description
Selects an option in the drop-down list. Nothing happens if the option passed as an argument does not exist.
example
click to expand
@newDropDown("warmth", "")
@ .add("hot", "lukewarm", "cold")
$ .select( "lukewarm" )
@,
@newText("Spring in Colorado is ")
@ .after( getDropDown("warmth") )
@ .print()
- Creates a drop-down list containing the options hot, lukewarm and cold, selects the option lukewarm and adds the list to the right of the text Spring in Colorado is, then prints everything onto the page.
dropdown.shuffle
syntax
.shuffle()
description
Shuffles the options that have been added to the DropDown so far. If you call shuffle
before settings.add
then it will have no effect.
example
click to expand
@newDropDown("warmth", "")
@ .add("hot", "lukewarm", "cold")
$ .shuffle()
@,
@newText("Spring in Colorado is ")
@ .after( getDropDown("warmth") )
@ .print()
@,
@getDropDown("warmth")
@ .wait()
- Creates a drop-down list containing the options hot, lukewarm and cold, shuffles them, adds the drop-down list to the right of the text Spring in Colorado is and prints everything onto the page, then waits until an option is selected from the drop-down list before proceeding.
dropdown.wait
syntax
.wait()
description
Waits until an option is selected from the drop-down list before proceeding.
example
click to expand
@newText("I want ")
@ .after( newDropDown("what", "").add("candy","to break free") )
@ .print()
@,
@newTimer("read", 2000)
@ .start()
@ .wait()
@,
@getDropDown("what")
@ .wait("first")
- Prints the text I want and, to its right, a drop-down list containing candy and to break free onto the page, then waits 2s and waits until an option is selected before proceeding. Since
wait
was called with the argument"first"
, execution will immediately proceed at the end of the 2s timer if an option was selected in the meantime, or it will wait for a selection to happen is no option has been selected at the end of the 2s timer.
Test commands
dropdown.test.selected
syntax
.test.selected()
description
Tests whether an option is selected. If you pass no option as an argument, then the test will succeed as long as any option is selected.
example
click to expand
@newDropDown("adjective", "")
@ .add( "hot" , "lukewarm" , "cold" )
@ .shuffle()
@ .print()
@ .wait()
@,
@getDropDown("adjective")
$ .test.selected( 1 )
$ .success(
$ newText("You selected the middle option (index-based).")
$ .print()
$ )
$ .failure(
$ getDropDown("adjective")
$ .test.selected( "lukewarm" )
$ .success(
$ newText("You selected the middle option (scale-based)")
$ .print()
$ )
$ )
- Creates a drop-down list with three options, hot, lukewarm and cold, shuffles the options, prints the list and waits until an option is selected before proceeding. After an option is selected, tests whether the option at index 1 was selected and, if so, will print You selected the middle option (index-based), otherwise will test whether the option lukewarm was selected and, if so, will print You selected the middle option (scale-based).