jsoneditor/test/test_schema.html

110 lines
2.0 KiB
HTML
Raw Permalink Normal View History

2016-01-11 22:44:03 +08:00
<!DOCTYPE HTML>
<html lang="en">
2016-01-11 22:44:03 +08:00
<head>
<meta charset="utf-8">
2016-01-11 22:44:03 +08:00
<link href="../dist/jsoneditor.css" rel="stylesheet" type="text/css">
<script src="../dist/jsoneditor.js"></script>
<style type="text/css">
body {
font: 10.5pt arial;
color: #4d4d4d;
line-height: 150%;
width: 600px;
2016-01-11 22:44:03 +08:00
padding-left: 40px;
}
html, body {
width: 100%;
padding: 0;
box-sizing: border-box;
}
2016-01-11 22:44:03 +08:00
code {
background-color: #f5f5f5;
}
#jsoneditor {
max-width: 600px;
width: 90%;
2016-01-11 22:44:03 +08:00
height: 500px;
}
</style>
</head>
<body>
<p>
Switch editor mode using the mode box.
Note that the mode can be changed programmatically as well using the method
<code>editor.setMode(mode)</code>, try it in the console of your browser.
</p>
<div id="jsoneditor"></div>
<script>
var container = document.getElementById('jsoneditor');
var schema = {
"title": "User",
2016-01-11 22:44:03 +08:00
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"gender": {
"enum": ["male", "female"]
},
2016-01-11 22:44:03 +08:00
"age": {
"description": "Age in years",
2019-03-08 03:50:05 +08:00
"examples": [18, 65],
2016-01-11 22:44:03 +08:00
"type": "integer",
"minimum": 0
},
"hobbies": {
"$ref": "hobbies.json"
2016-01-11 22:44:03 +08:00
}
},
"required": ["firstName", "lastName"]
};
var hobbiesSchema = {
"type": "array",
"items": {
"type": "string"
}
};
2016-01-11 22:44:03 +08:00
var options = {
mode: 'tree',
modes: ['code', 'form', 'text', 'tree', 'view', 'preview'], // allowed modes
2016-01-11 22:44:03 +08:00
onError: function (err) {
console.error(err);
},
schema: schema,
schemaRefs: {"hobbies.json": hobbiesSchema}
2016-01-11 22:44:03 +08:00
};
var json = {
"firstName": "Jos",
"lastName": "de Jong",
gender: null,
2016-01-11 22:44:03 +08:00
"age": 34.2,
"hobbies": [
"programming",
"movies",
"bicycling"
]
};
var editor = new JSONEditor(container, options, json);
console.log('json', json);
console.log('schema', schema);
</script>
</body>
</html>