forked from joshcanhelp/php-form-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phpFormBuilder.js
78 lines (74 loc) · 3.13 KB
/
phpFormBuilder.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
document.addEventListener("DOMContentLoaded", function() {
var varFlagObjects = ${objFlags};
var ${objectname} = {
getForm: function() {
var e = document.getElementById("${f}");
return void 0 !== e && null != e || (e = document.getElementsByTagName("form")[0]), void 0 !== e && null != e && e
},
getGroups: function() {
var e = document.querySelectorAll("[group]"),
t = "",
r = {};
return e.forEach(e => {
void 0 !== (t = e.getAttribute("group")) && (r[t] = "")
}), 0 != r.length && Object.keys(r).reverse()
},
buildGroupFieldsets: function() {
var e = ${objectname}.getForm();
e && ${objectname}.getGroups().forEach(t => {
let r = document.createElement("fieldset"),
o = document.createElement("legend");
o.innerHTML = t, r.appendChild(o);
let n = '.form_field_wrap[group="' + t + '"]';
document.querySelectorAll(n).forEach(e => {
r.append(e)
}), e.insertBefore(r, e.firstChild)
})
},
buildFlags: function(){
/*
- Creates the flag checkboxes
plus a hidden control to receive the values.
- Creates the click events
*/
varFlagObjects.forEach(t => {
// there's a div up there with the id t.id
// the text inside it is the current record's flag value
let C = document.getElementById(t.id);
let curFlag = parseInt(C.innerText);
let e = C.parentNode;
C.remove();
let D = JSON.parse(t.values);
let f = document.createElement("input");
f.type = 'hidden'; // make this 'text' if you want to see the thing in action
f.value = curFlag;
f.id = t.id;
f.name = t.id;
e.append(f);
D.forEach(a => {
let b = document.createElement("label");
b.innerHTML = a.caption;
let c = document.createElement("input");
c.type = 'checkbox';
c.value = a.value;
c.setAttribute('feeds', t.id);
c.checked = ( (a.value & curFlag) != 0 );
c.onclick = function(){
let newflag = 0;
let g = document.querySelectorAll('[feeds="' + t.id + '"]');
g.forEach(h => {
if(h.checked) {
newflag += (h.value * 1);
}
});
f.value = newflag;
};
e.append(b);
e.append(c);
});
});
}
};
${objectname}.buildGroupFieldsets();
${objectname}.buildFlags();
});