-
Notifications
You must be signed in to change notification settings - Fork 0
/
4.js
76 lines (73 loc) · 1.64 KB
/
4.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
function parseObjectToForm(o, dom)
{
var form = document.createElement('form')
var fc = new formCreator();
for(var i in o)
{
form.appendChild(fc.createField(o[i]));
}
dom.appendChild(form);
}
var formCreator = function()
{
this.createField = function(o)
{
var div = document.createElement('div');
var e;
if(o.type == 'text')
{
div.appendChild(this.createLabel(o.name));
e = document.createElement('input');
e.type = 'text';
}
else if(o.type == 'radio')
{
div.appendChild(this.createP(o));
e = document.createElement('div');
for(var i in o.values)
{
var value = o.values[i];
e.appendChild(this.createLabel(value));
var r = document.createElement('input');
r.type = 'radio';
r.name = o.name.toLowerCase();
e.appendChild(r);
}
}
else if(o.type == 'list')
{
div.appendChild(this.createP(o));
var e = document.createElement('ul');
for(var i in o.list)
{
var list_element = document.createElement('li');
list_element.appendChild(this.createField(o.list[i]));
e.appendChild(list_element);
}
div.appendChild(e);
}
else if(o.type == 'date')
{
console.log(o);
div.appendChild(this.createLabel(o.name));
e = document.createElement('input');
e.type = 'date';
}
e.id = o.name.toLowerCase();
div.appendChild(e);
return div;
}
this.createLabel = function(o)
{
var l = document.createElement('label');
l.innerHTML = o;
l.htmlFor = o.toLowerCase();
return l;
}
this.createP = function(o)
{
var p = document.createElement('p');
p.innerHTML = o.name;
return p;
}
}