MultipleChoice.showif#
- property MultipleChoice.showif: dict[source]#
Conditions that have to be met for the element to be shown.
The showif dictionary can contain multiple conditions as key- value-pairs. The element will only be shown, if all conditions are met. You can use all names that show up in the main dataset. That includes:
The names of all input elements that were shown before the current page
The names of all input elements on the current page
The experiment metadata, including exp_condition, exp_start_time, and more. See
Experiment.metadata
Note
If you wish to implement more sophisticated conditions (e.g. linking conditions with ‘or’ instead of ‘and’), you can do so by using if-statements in an on_first_show or on_each_show page-hook.
Those conditions will not work for elements on the same page though. If you want to create complex showif conditions depending on elements on the same page, you have to implement them in JavaScript yourself. See
add_js()
andJavaScript
for information on how to add JavaScript.Examples
This is a simple showif based on experiment condition. The text element in this example will only be shown to subjects in the condition “one”:
import alfred3 as al exp = al.Experiment() @exp.setup def setup(exp): exp.condition = al.random_condition("one", "two") @exp.member class MyPage(al.Page): def on_exp_access(self): self += al.Text("This is text", showif={"exp_condition": "one"})
This is a more complex condition using the hook method. The text element on page2 will only be show to subjects, if they spent more than 20 seconds on page1:
import alfred3 as al exp = al.Experiment() exp += al.Page(name="FirstPage") @exp.member class SecondPage(al.Page): def on_first_show(self): if sum(self.exp.page1.durations) > 20: self += al.Text("This is text")
See also
Page hooks
- Type