|
@@ -23,6 +23,39 @@ def main_demo() -> None:
|
|
|
on_change=lambda e: ui.notify(f'Change: {e}'))
|
|
|
|
|
|
|
|
|
+@doc.demo('Validation', '''
|
|
|
+ You can use the `schema` parameter to define a [JSON schema](https://json-schema.org/) for validating the data being edited.
|
|
|
+ In this demo, the editor will warn if the data does not match the schema:
|
|
|
+
|
|
|
+ - `id` must be an integer
|
|
|
+ - `name` must be a string
|
|
|
+ - `price` must be a number greater than 0
|
|
|
+''')
|
|
|
+def schema_demo() -> None:
|
|
|
+ schema = {
|
|
|
+ 'type': 'object',
|
|
|
+ 'properties': {
|
|
|
+ 'id': {
|
|
|
+ 'type': 'integer',
|
|
|
+ },
|
|
|
+ 'name': {
|
|
|
+ 'type': 'string',
|
|
|
+ },
|
|
|
+ 'price': {
|
|
|
+ 'type': 'number',
|
|
|
+ 'exclusiveMinimum': 0,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'required': ['id', 'name', 'price'],
|
|
|
+ }
|
|
|
+ data = {
|
|
|
+ 'id': 42,
|
|
|
+ 'name': 'Banana',
|
|
|
+ 'price': 15.0,
|
|
|
+ }
|
|
|
+ ui.json_editor({'content': {'json': data}}, schema=schema)
|
|
|
+
|
|
|
+
|
|
|
@doc.demo('Run methods', '''
|
|
|
You can run methods of the JSONEditor instance using the `run_editor_method` method.
|
|
|
This demo shows how to expand and collapse all nodes and how to get the current data.
|