MultipleChoiceButtons#
- class alfred3.element.input.MultipleChoiceButtons(*choice_labels, button_round_corners: bool = False, **kwargs)[source]#
Bases:
alfred3.element.input.MultipleChoice
,alfred3.element.input.SingleChoiceButtons
A prettier
MultipleChoice
element with buttons instead of checkbox inputs.To make them distinct from single choice buttons, multiple choice buttons don’t have rounded corners by default.
- Parameters
*choice_labels – Variable numbers of choice labels. See
ChoiceElement
for details.min – Minimum (maximum) number of choices that need to be selected, if any are selected (does not imply force_input=True).
max – Minimum (maximum) number of choices that need to be selected, if any are selected (does not imply force_input=True).
select_hint – Hint to be displayed, if the requirement of minimum or maximum number of selected fields is not reached. Defaults to the experiment-wide value specified in config.conf.
default – Can be a single integer, or a list of integers which indicate the choices that should be selected by default. Counting starts at 1.
**kwargs –
Inherited keyword arguments
align
Horizontal alignment of text in the element. Does not usually apply to labels. Think of it as an alignment that applies to the innermost layer of an element (while labels are generally located at outer layers). See
LabelledElement
for more on labelled elements. Can be left (default), center, right, or justify.button_round_corners
A boolean switch to toggle whether buttons should be displayed with rounded corners (True).
button_style
Can be used for quick color-styling, using Bootstraps default color keywords: btn-primary, btn-secondary, btn-success, btn-info, btn-warning, btn-danger, btn-light, btn-dark. You can also use the outline variant to get outlined buttons (eg. btn-outline-secondary). If you specify a single string, this style is applied to all buttons in the element. If you supply a list, you can define individual styles for each button. If you supply a list that is shorter than the list of labels, the last style will be repeated for remaining buttons. Advanced users can supply their own CSS classes for button-styling.
button_width
Can be used to manually define the width of buttons. If you supply a single string, the same width will be applied to all buttons in the element. If you supply auto, button width will be determined automatically. You can also supply a list of specific widths for each individual button. You must specify a unit, e.g. 140px. Defaults to equal.
debug_value
Value to be used in debug mode. If None (default), alfred will first try to use the elements ordinary default value. If there is no default value, alfred will read the debug value from the config.conf.
description
An additional description of the element. This will show up in the alfred-generated codebook. It has no effect on the display of the experiment, as it only serves as a descriptor for humans.
font_size
Font size for text in the element. You can use a keyword or an exact specification. The available keywords are tiny, small, normal, big, and huge. The exact specification shoul ideally include a unit, such as 1rem, or 12pt. If you supply an integer without a unit, a unit of pt will be assumed. Defaults to normal.
force_input
If True, users can only progress to the next page if they enter data into this field. Note that a
NoValidationSection
or similar sections might overrule this setting. A general, experiment-wide setting for force_input can be placed in the config.conf (section general). That setting is used by default and can be overruled here for individual elements. Defaults to False. The experiment-wide default can be changed in config.conf.height
Vertical height of the elements display area. Supply a string with a unit, e.g. 80px. Usually, the default is fine. For adding vertical space to a page, you should prefer the
VerticalSpace
element, as it is sematically more clear.instance_log
If True, the element will use an instance-specific logger, thereby allowing detailed fine- tuning of its logging behavior.
layout
Can be one of the following: 1) An instance of
RowLayout
, or 2) a tuple of integers, specifying the allocation of horizontal space between leftlab, main element widget and rightlab on small screens upwards. Option 1) offers fine-tuned flexibility, 2) uses a default RowLayout and changes theRowLayout.width_sm
attribute. By default, the layout is set automatically depending on the specification of the left and right labels.name
Name of the element. This should be a unique identifier. It will be used to identify the corresponding data in the final data set.
no_input_hint
Hint to be displayed if force_input set to True and no user input registered. Defaults to the experiment-wide default value specified in config.conf.
position
Horizontal position of the full element on the page. Values can be left, center (default), end, or any valid value for the justify-content flexbox utility. Takes effect only, when the element is not full-width.
prefix
Prefix for the input field.
save_data (bool)
If False, this element will not save any data to the experiment data and will not appear in the codebook.
showif
A dictionary, defining conditions that must be met for the element to be shown. The conditions take the form of key-value pairs, where each key is an element name and the value is the required input. See
showif
for details.suffix
Suffix for the input field.
toplab, bottomlab, leftlab, rightlab
Labels above, below, left and right of the element.
vertical
Boolean switch, indicating whether the choices should be listed vertically. Defaults to False, i.e. horizontal display.
width
Defines the horizontal width of the element from small screens upwards. It is always full-width on extra small screens. Possible values are narrow, medium, wide, and full. For more detailed control, you can define the
element_width
attribute.
Notes
This element saves and returns not a single value, but a dictionary of values. Each choice is represented by a key, and the corresponding value is True, if the choice was selected and False otherwise.
The keys are of the form
choicei
, wherei
is a placeholer for the number of the choice, i.e.choice1
for the first choice.See also
See
MultipleChoice
andMultipleChoiceBar
for nice-looking buttons and a button-bar of multiple choices.See
MultipleChoiceList
for a a list that allows multiple selections.See
SingleChoice
,SingleChoiceButtons
, andSingleChoiceBar
for single choice elements.See
SubmittingButtons
for single choice buttons that trigger a forward move on click.
Examples
Multiple choice buttons:
import alfred3 as al exp = al.Experiment() @exp.member class Demo(al.Page): def on_exp_access(self): self += al.MultipleChoiceButtons("Yes", "No", "Maybe", name="m1")
Accessing the input to a MultipleChoiceButtons element:
import alfred3 as al exp = al.Experiment() @exp.member class Demo(al.Page): def on_exp_access(self): self += al.MultipleChoiceButtons("a", "b", "c", toplab="Choose one or more", name="c1") @exp.member class Show(al.Page): def on_first_show(self): choices = self.exp.values.get("c1") self += al.Text(f"Your answer is saved like this: {choices}")
Methods
Adds CSS to the element.
Adds Javascript to the element.
Tells the element that it was added to an experiment.
If choice labels are element instances, they are added to the page to enable their full functionality.
Abstract method for the definition of the individual choices belonging to this element.
Hook for computations for preparing an element's web widget.
Renders the element template
element_template
.Sets the
input
data.Method for validation of input to the element.
Attributes
Base template for the element, which will be used to hold the rendered element template.
Label below of the main element widget.
CSS class for the button group
See documentation for the initialization argument.
A boolean switch to toggle whether buttons should be layoutet as a connected toolbar (True), or as separate neighbouring buttons (False, default).
Stored list of choice labels.
Information about the element in dictionary form.
List of bootstrap column widths at different screen sizes.
Shortcut for accessing the element's corrective hints.
Returns the name the element container's CSS class.
Returns the name of the element's CSS class.
A list of tuples, which contain a priority and CSS code.
A list of tuples, which contain a priority and an url pointing to CSS code.
Dictionary of element data.
Boolean flag, indicating whether debug mode is enabled and default values should be set.
Value to be used as a default in debug mode.
Default value of this element.
Default hint if subject input is missing in force_entry elements.
Detailed description of this element to be added to the automatically generated codebook
A boolean flag, indicating whether the element is disabled A disabled input element is shown and displays its input value, but subjects cannot enter any data.
If True (default), the element will be displayed as usual on its own.
The element's specific, inner template.
Returns a string of column width definitions.
Switch for turning the interpretation of emoji shortcodes in the choice labels off, if necessary.
The experiment session to which this element belongs.
Alias for
exp
Font size
If True, subjects must fill this element to proceed.
A
MessageManager
, handling the corrective hints for this element.Dictionary of subject inputs.
A list of tuples, which contain a priority and Javascript.
A list of tuples, which contain a priority and an url pointing to JavaScript.
Returns the labels in a single, nicely formatted string.
Controls the allocation of horizontal space between the left and right label, as well as the main element.
Label to the left of the main element widget.
Unique identifier for the element.
Hint for subjects, if they left a force_input field empty.
The page to which this element belongs.
Position of the whole element on the page.
A string or element, serving as prefix.
Label to the right of the main element widget.
The direct parent section of this element's page.
Hint for participants.
String, giving the exact position in the experiment.
Boolean, indicating whether the element is meant to be shown.
Flag, indicating whether corrective hints regarding this element should be shown.
Conditions that have to be met for the element to be shown.
A string or element, serving as suffix.
Dictionary of data to be passed on to jinja templates.
Label above of the main element widget.
String, giving the exact position in the experiment.
Choice type (e.g.
Attribute defining, whether the element is displayed vertically.
The element's rendered html code for display on a page.
Element width