Skip to main content

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

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]
initial_valueThe initial value to display to the user. Defaults to None.str
minThe minimum number of items that must be selected. Defaults to 0.int
maxThe maximum number of items that can be selected. Defaults to the number of options.int
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
List[str]The selected values