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
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 |
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 |
initial_value | The initial values of the selection. Defaults to []. | [] |
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 |
---|---|
Union[list, any] | The values/value selected by the user |