-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
114 lines (96 loc) · 2.11 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Test</title>
<script src="htmlEncode.js"></script>
<script src="tv4.js"></script>
<script src="jsb.js"></script>
<style>
@import url("jsb.css");
</style>
</head>
<body>
<div id="form"></div>
<button id="save">Save</button>
<button id="validate">Validate</button>
<script>
var schema = {
"Other": {
"properties": {
"name": {
"type": [ "string", "array" ],
"required": true,
"items": {
"type": "string"
},
"minItems": 1,
"maxItems": 3
},
"detail": {
"type": "object",
"properties": {
"description": {
"type": "string",
"required": true,
"large": true
},
"type": {
"type": "string",
"required": true,
"enum": [
"unknown", "free", "paid"
]
}
}
}
}
},
"Example": {
"extends": "Other",
"properties": {
"private": {
"type": "boolean",
"description": "If true the this item will be considered private"
},
"other": {
"type": "array",
"items": {
"$ref": "Other"
}
},
"age": {
"type": "number"
}
}
},
};
var data = {
"name": [ "foo", "bar" ],
"private": true,
"age": 77,
"detail": {
"description": "An example object",
"type": "free"
}
};
var f = document.getElementById('form');
var jsb = new JSB(f, data);
jsb.setSchema(schema["Example"], function(name) {
console.log("Load ref:", name);
return(schema[name]);
});
jsb.render();
document.getElementById('save').addEventListener('click', function(e) {
console.log(JSON.stringify(jsb, null, " "));
});
document.getElementById('validate').addEventListener('click', function(e) {
if (jsb.validate()) {
alert('Yup, all good');
} else {
alert('Sorry, not valid');
}
});
</script>
</body>
</html>