input_documentation.py 1.0 KB

12345678910111213141516171819202122232425262728
  1. from nicegui import ui
  2. from ..documentation_tools import text_demo
  3. def main_demo() -> None:
  4. ui.input(label='Text', placeholder='start typing',
  5. on_change=lambda e: result.set_text('you typed: ' + e.value),
  6. validation={'Input too long': lambda value: len(value) < 20})
  7. result = ui.label()
  8. def more() -> None:
  9. @text_demo('Autocompletion', '''
  10. The `autocomplete` feature provides suggestions as you type, making input easier and faster.
  11. The parameter `options` is a list of strings that contains the available options that will appear.
  12. ''')
  13. async def autocomplete_demo():
  14. options = ['AutoComplete', 'NiceGUI', 'Awesome']
  15. ui.input(label='Text', placeholder='start typing', autocomplete=options)
  16. @text_demo('Clearable', '''
  17. The `clearable` prop from [Quasar](https://quasar.dev/) adds a button to the input that clears the text.
  18. ''')
  19. async def clearable():
  20. i = ui.input(value='some text').props('clearable')
  21. ui.label().bind_text_from(i, 'value')