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
Name | Description | Type |
---|---|---|
label | The label to display to the user | str |
options | The options to display to the user, eg. ['Option 1', 'Option 2'] or [{'label': 'Option 1', 'value': '1'}, {'label': 'Option 2', 'value': '2'}] | List[AbstraOption] |
multiple | Whether the user can select multiple options. Defaults to False. | bool |
initial_value | The initial value to display to the user. Defaults to []. | str or list |
placeholder | The placeholder text to display to the user. Defaults to "Choose an option". | str |
min | The minimal amount of options that should be selected. Defaults to None. | number |
max | The maximum amount of options that should be selected. Defaults to None. | number |
disabled | whether the input is disabled. Defaults to False. | bool |
required | Whether the input is required or not eg. "this field is required". Defaults to True. | Union[bool, str] |
hint | A tooltip displayed to the user. Defaults to None. | str |
full_width | Whether the input should use full screen width. Defaults to False. | bool |
button_text | What text to display on the button when the widget is not part of a Page. Defaults to 'Next'. | str |
Return Values
Type | Description |
---|---|
str | The value selected by the user |