File size: 826 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 |
# Form / Combobox / Trigger
# To handle live changes to a #combobox, enable the `trigger` attribute.
# #combobox #trigger
# ---
from h2o_wave import main, app, Q, ui
combobox_choices = ['Cyan', 'Magenta', 'Yellow', 'Black']
def get_form_items(choice: str):
return [
ui.combobox(name='combobox', trigger=True, label='Enter or choose a color', placeholder='Color...', value='Blue',
choices=combobox_choices),
ui.label('Sent to server'),
ui.text(choice),
]
@app('/demo')
async def serve(q: Q):
if not q.client.initialized:
q.page['example'] = ui.form_card(box='1 1 4 10', items=get_form_items(''))
q.client.initialized = True
if q.args.combobox is not None:
q.page['example'].items = get_form_items(q.args.combobox)
await q.page.save()
|