File size: 1,899 Bytes
2b4d75c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# Form / Combobox
# Use comboboxes to allow users to either choose between available choices or indicate a choice by free-form editing.
# #form #combobox
# ---
from h2o_wave import main, app, Q, ui
combobox_choices = ['Cyan', 'Magenta', 'Yellow', 'Black']
@app('/demo')
async def serve(q: Q):
if q.args.show_inputs:
q.page['example'].items = [
ui.text(f'combobox={q.args.combobox}'),
ui.text(f'combobox_required={q.args.combobox_required}'),
ui.text(f'combobox_disabled={q.args.combobox_disabled}'),
ui.text(f'combobox_error={q.args.combobox_error}'),
ui.text(f'combobox_multivalued={q.args.combobox_multivalued}'),
ui.button(name='show_form', label='Back', primary=True),
]
else:
q.page['example'] = ui.form_card(box='1 1 4 7', items=[
ui.combobox(name='combobox', label='Enter or choose a color', placeholder='Color...', value='Blue',
choices=combobox_choices),
ui.combobox(name='combobox_required', label='Enter or choose a color', placeholder='Color...', value='Blue',
choices=combobox_choices, required=True),
ui.combobox(name='combobox_disabled', label='Enter or choose a color', placeholder='Color...', value='Blue',
choices=combobox_choices, disabled=True),
ui.combobox(name='combobox_error', label='Enter or choose a color', placeholder='Color...', value='Blue',
choices=combobox_choices, error='This combobox has an error!'),
ui.combobox(name='combobox_multivalued', label='Enter or choose a color (multi select)', placeholder='Color...', values=['Blue', 'Magenta'],
choices=combobox_choices),
ui.button(name='show_inputs', label='Submit', primary=True),
])
await q.page.save()
|