number_documentation.py 1.2 KB

123456789101112131415161718192021222324252627282930
  1. from nicegui import ui
  2. from ...model import UiElementDocumentation
  3. class NumberDocumentation(UiElementDocumentation, element=ui.number):
  4. def main_demo(self) -> 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. def more(self) -> None:
  9. @self.demo('Clearable', '''
  10. The `clearable` prop from [Quasar](https://quasar.dev/) adds a button to the input that clears the text.
  11. ''')
  12. def clearable():
  13. i = ui.number(value=42).props('clearable')
  14. ui.label().bind_text_from(i, 'value')
  15. @self.demo('Number of decimal places', '''
  16. You can specify the number of decimal places using the `precision` parameter.
  17. A negative value means decimal places before the dot.
  18. The rounding takes place when the input loses focus,
  19. when sanitization parameters like min, max or precision change,
  20. or when `sanitize()` is called manually.
  21. ''')
  22. def integer():
  23. n = ui.number(value=3.14159265359, precision=5)
  24. n.sanitize()