number_documentation.py 973 B

123456789101112131415161718192021222324252627282930313233
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.number)
  4. def main_demo() -> None:
  5. ui.number(label='Number', value=3.1415927, format='%.2f',
  6. on_change=lambda e: result.set_text(f'you entered: {e.value}'))
  7. result = ui.label()
  8. @doc.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. @doc.demo('Number of decimal places', '''
  15. You can specify the number of decimal places using the `precision` parameter.
  16. A negative value means decimal places before the dot.
  17. The rounding takes place when the input loses focus,
  18. when sanitization parameters like min, max or precision change,
  19. or when `sanitize()` is called manually.
  20. ''')
  21. def integer():
  22. n = ui.number(value=3.14159265359, precision=5)
  23. n.sanitize()
  24. doc.reference(ui.number)