How to refer to checklist value #1362
Answered
by
mturoci
gbethardy-h2oai
asked this question in
Q&A
-
How does one refer to the checklist values in code to control processing? For example if item 1 is checked perform some operation, if item 2 is checked perform another, etc. |
Beta Was this translation helpful? Give feedback.
Answered by
mturoci
Apr 20, 2022
Replies: 1 comment 3 replies
-
Checklist is for gathering multiple selections, for single selections you might want to use checkbox instead. Maybe you are looking for something like: @app('/demo')
async def serve(q: Q):
if not q.client.initialized or q.args.show_form:
q.page['example'] = ui.form_card(box='1 1 4 10', items=[
ui.checklist(name='checklist', label='Choices',
choices=[ui.choice(name=x, label=x) for x in ['Egg', 'Bacon', 'Spam']]),
ui.button(name='show_inputs', label='Submit', primary=True),
])
q.client.initialized = True
# Check if specified item is selected.
if q.args.checklist and 'Egg' in q.args.checklist:
q.page['example'].items = [
ui.text('You have selected an egg! Make an omelette!'),
ui.button(name='show_form', label='Back', primary=True),
]
await q.page.save() Or with checkbox: @app('/demo')
async def serve(q: Q):
if not q.client.initialized or q.args.show_form:
q.page['example'] = ui.form_card(box='1 1 4 10', items=[
ui.checkbox(name='checkbox1', label='Checkbox1'),
ui.button(name='show_inputs', label='Submit', primary=True),
])
q.client.initialized = True
# Check if specified checkbox is selected.
if q.args.checkbox1:
q.page['example'].items = [
ui.text('You have selected Checkbox1'),
ui.button(name='show_form', label='Back', primary=True),
]
await q.page.save() |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
mturoci
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Checklist is for gathering multiple selections, for single selections you might want to use checkbox instead. Maybe you are looking for something like: