select_documentation.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from nicegui import ui
  2. from ..documentation_tools import text_demo
  3. def main_demo() -> None:
  4. select1 = ui.select([1, 2, 3], value=1)
  5. select2 = ui.select({1: 'One', 2: 'Two', 3: 'Three'}).bind_value(select1, 'value')
  6. def more() -> None:
  7. @text_demo('Search-as-you-type', '''
  8. You can activate `with_input` to get a text input with autocompletion.
  9. The options will be filtered as you type.
  10. ''')
  11. def search_as_you_type():
  12. continents = [
  13. 'Asia',
  14. 'Africa',
  15. 'Antarctica',
  16. 'Europe',
  17. 'Oceania',
  18. 'North America',
  19. 'South America',
  20. ]
  21. ui.select(options=continents, with_input=True,
  22. on_change=lambda e: ui.notify(e.value)).classes('w-40')
  23. @text_demo('Multi selection', '''
  24. You can activate `multiple` to allow the selection of more than one item.
  25. ''')
  26. def multi_select():
  27. names = ['Alice', 'Bob', 'Carol']
  28. ui.select(names, multiple=True, value=names[:2], label='comma-separated') \
  29. .classes('w-64')
  30. ui.select(names, multiple=True, value=names[:2], label='with chips') \
  31. .props('use-chips').classes('w-64')