-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.html
54 lines (53 loc) · 2.16 KB
/
example.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
<!DOCTYPE html><html><head><script type="text/javascript" src="./build/build.js"></script><script type="text/javascript">function init() {
var syncModel = require('sync-model');
var model = require('component-model');
var validator = require('Baggz-amanda')('json');
var User = model('user')
.attr('name', {
required: true,
type: 'string'
})
.attr('email', {
required: true,
type: 'string',
format: 'email'
})
.attr('address', {
type: 'object',
properties: {
street: {
required: true,
type: 'string'
},
zipcode: {
required: true,
type: 'string'
},
city: {
required: true,
type: 'string'
}
}
})
.attr('orders', {
type: 'array',
items: {
type: 'object',
properties: {
amount: {
required: true,
type: 'integer'
},
name: {
required: true,
type: 'string'
}
}
}
});
function callback (errors) {
console.log('validaton errors: ', errors);
}
var user = syncModel(document.querySelector('form'), User, callback, this);
console.log(user);
};</script></head><body onload="init()"><form><span>Name: </span><input name="name" value="Hans"><br><span>Email:</span><input name="email" value="h@ns"><br><span>Address:</span><input name="address.street" value="streetname"><input name="address.zipcode" value="zipcode"><input name="address.city" value="city"><br><span>Orders:</span><input name="orders.0.amount" value="1"><input name="orders.0.name" value="Socks"><br><input name="orders.1.amount" value="2"><input name="orders.1.name" value="Shoes"></form></body></html>