forked from josdejong/jsoneditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_enum_2.html
123 lines (113 loc) · 2.93 KB
/
test_enum_2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE HTML>
<html>
<head>
<title>JSONEditor | template + enums</title>
<link href="../dist/jsoneditor.css" rel="stylesheet" type="text/css">
<script src="../dist/jsoneditor.js"></script>
<style type="text/css">
#jsoneditor {
width: 500px;
height: 700px;
background: white;
}
p {
width: 500px;
font-family: sans;
}
</style>
</head>
<body>
<p>Demonstrates a template with JSON schema validation. To use: click the context menu of the first or second employee, click insert or append, click "Employee".</p>
<p><a href="https://github.com/josdejong/jsoneditor/issues/473">See github issue #473</a></p>
<div id="jsoneditor"></div>
<script>
var schema = {
"title": "Example Schema",
"type": "array",
"items": {
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"gender": {
"enum": ["male", "female"]
},
"age": {
"description": "Age in years",
"type": "integer",
"minimum": 0
},
"job": {
"$ref": "job"
}
},
"required": ["firstName", "lastName"]
}
};
var job = {
"title": "Job description",
"type": "object",
"properties": {
"company": {
"type": "string"
},
"role": {
"type": "string"
}
}
};
var json = [
{
firstName: 'John',
lastName: 'Doe',
gender: 'male',
age: 28,
job: {
company: 'freelance',
role: 'developer'
}
},
{
firstName: 'Susan',
lastName: 'Smith',
gender: null,
age: 28,
job: {
company: 'freelance',
role: 'sales'
}
}
];
var templates = [
{
text: 'Employee',
title: 'Insert a new employee',
className: 'jsoneditor-type-object',
field: 'employee',
value: {
firstName: '',
lastName: '',
gender: '',
age: '',
job: {
company: '',
role: ''
}
}
}
]
var options = {
schema: schema,
schemaRefs: {"job": job},
templates: templates
};
// create the editor
var container = document.getElementById('jsoneditor');
var editor = new JSONEditor(container, options, json);
</script>
</body>
</html>