Checklist
Displays a checklist allowing multiple item selections.
Examples
Basic Example
Basic use of read_checklist
from abstra.forms import read_checklist
ans = read_checklist(
"Which programming language have you worked with?",
["Python", "JavaScript", "Go", "Elixir", "Haskell"],
)
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_checklist
ans = read_checklist(
"What are the solutions to the equation x^2 + 3x + 2 = 0?",
[
{"label": "-1", "value": "a"},
{"label": "-2", "value": "b"},
{"label": "0 and -1", "value": "c"},
{"label": "0 and 1", "value": "d"},
{"label": "None of the above", "value": "e"},
],
)
# ans = ["a", "b"]
Set the range of selections
Set the minimum and maximum number of selections.
from abstra.forms import read_checklist
ans = read_checklist(
"What are your favorite programming languages? Choose up to 3.",
["Python", "JavaScript", "Go", "Elixir", "Haskell"],
min=1,
max=3,
)
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] |
initial_value | The initial value to display to the user. Defaults to None. | str |
min | The minimum number of items that must be selected. Defaults to 0. | int |
max | The maximum number of items that can be selected. Defaults to the number of options. | int |
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 |
---|---|
List[str] | The selected values |