Skip to main content

Multiple Choice

Offers multiple choice selections with single or multi-select options.

Examples

Basic Example

Basic use of read_multiple_choice

from abstra.forms import read_multiple_choice

ans = read_multiple_choice(
"Which programming language do you prefer?",
["Python", "JavaScript"],
)
# ans = "Python" or "JavaScript"

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_multiple_choice

ans = read_multiple_choice(
"Which programming language do you prefer?",
[{"label": " Python", "value": "py"}, {"label": "JavaScript", "value": "js"}],
)
# ans = "py" or "js"

Checkboxes

Use multiple=true when you want allow users to select more than one option. This will make it returns a list.

from abstra.forms import read_multiple_choice

ans = read_multiple_choice(
"What features do you love?", ["forms", "jobs", "hooks"], multiple=True
)
# ans = ["forms", "jobs", "hooks"]

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
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
initial_valueThe initial indexes of the selection. Defaults to [].[]
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
end_programWhether the program should end after the widget is shown. Defaults to False.bool
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
Union[list, any]The values/value selected by the user