number_documentation.py 839 B

1234567891011121314151617181920212223242526
  1. from nicegui import ui
  2. from ..documentation_tools import text_demo
  3. def main_demo() -> None:
  4. ui.number(label='Number', value=3.1415927, format='%.2f',
  5. on_change=lambda e: result.set_text(f'you entered: {e.value}'))
  6. result = ui.label()
  7. def more() -> None:
  8. @text_demo('Clearable', '''
  9. The `clearable` prop from [Quasar](https://quasar.dev/) adds a button to the input that clears the text.
  10. ''')
  11. def clearable():
  12. i = ui.number(value=42).props('clearable')
  13. ui.label().bind_text_from(i, 'value')
  14. @text_demo('Integer', '''
  15. Coerce the returned value to be integer instead of the default float.
  16. ''')
  17. def integer():
  18. i = ui.number(value=38)
  19. ui.button('Check number type', on_click=lambda: ui.notify(f'{i.value=} is of type {type(i.value)}'))