-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
87 lines (82 loc) · 1.77 KB
/
test.js
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
var firstForm = new Reformer({
fields: [
{
name: 'first_name',
label: 'First Name',
placeholder: 'Something',
required: true,
autocomplete: 'off'
},
{
name: 'last_name',
label: 'Last Name',
tests: [
{
test: function (val) {
return false;
},
message: 'something will always go wrong'
},
{
test: function (val) {
return val && val.toString().length > 2;
},
message: 'Must be at least three characters.'
}
],
required: true,
errorPlacement: 'after'
},
{
name: 'description',
label: 'Description',
widget: 'textarea',
tests: [
{
test: function (val) {
return val && val.toString().length > 2;
},
message: 'Must be at least three characters.'
}
],
required: true
}
],
submit: function (vals) {
console.log(vals);
},
error: function (vals) {
console.log('error', vals);
}
});
var customForm = new Reformer({
fields: [
{
fieldContainer: 'specialField',
name: 'specialThing',
tests: [
{
message: "must be longer than 5 characters",
test: function (val) {
return val && val.length > 5;
}
}
]
}
],
submit: function (vals) {
console.log('submit', vals)
},
error: function (vals) {
console.log('err', vals);
}
});
document.addEventListener('DOMContentLoaded', function () {
firstForm.render({
formEl: document.getElementById('myForm'),
fieldContainer: document.getElementById('fields'),
});
customForm.render({
formEl: document.getElementById('customForm')
});
}, false);