Skip to main content

Dropdown

Provides a dropdown menu for single or multiple selections.

Examples

Basic Example

Basic use of read_dropdown

from abstra.forms import read_dropdown

ans = read_dropdown(
"Choose a color",
["Red", "Green", "Blue"],
)
# ans = "Red", "Green" or "Blue"

Label and value dict

Use a dictionary to specify the label and value of each option. The label will be displayed to the user, and the value will be returned by the widget.

from abstra.forms import read_dropdown

ans = read_dropdown(
"Choose a color",
[
{"label": "Red", "value": "R"},
{"label": "Green", "value": "G"},
{"label": "Blue", "value": "B"},
],
)
# ans = "R", "G" or "B"

Parameters

NameDescriptionType
labelThe label to display to the userstr
optionsThe options to display to the user, eg. ['Option 1', 'Option 2'] or [{'label': 'Option 1', 'value': '1'}, {'label': 'Option 2', 'value': '2'}]List[AbstraOption]
multipleWhether the user can select multiple options. Defaults to False.bool
initial_valueThe initial value to display to the user. Defaults to [].str or list
placeholderThe placeholder text to display to the user. Defaults to "Choose an option".str
minThe minimal amount of options that should be selected. Defaults to None.number
maxThe maximum amount of options that should be selected. Defaults to None.number
disabledwhether the input is disabled. Defaults to False.bool
requiredWhether the input is required or not eg. "this field is required". Defaults to True.Union[bool, str]
hintA tooltip displayed to the user. Defaults to None.str
full_widthWhether the input should use full screen width. Defaults to False.bool
button_textWhat text to display on the button when the widget is not part of a Page. Defaults to 'Next'.str

Return Values

TypeDescription
strThe value selected by the user