MCPcopy
hub / github.com/bitwiseshiftleft/sjcl / formHandler

Function formHandler

demo/form.js:71–117  ·  view source on GitHub ↗
(formName, enterActions)

Source from the content-addressed store, hash-verified

69};
70
71function formHandler(formName, enterActions) {
72 var i, els = [], tmp, name;
73 this._elNames = [];
74
75 tmp = document.getElementById(formName).getElementsByTagName('input');
76 for (i=0; i<tmp.length; i++) { els.push(tmp[i]); }
77
78 tmp = document.getElementById(formName).getElementsByTagName('textarea');
79 for (i=0; i<tmp.length; i++) { els.push(tmp[i]); }
80
81 for (i=0; i<els.length; i++) {
82 name = els[i].name || els[i].id;
83
84 /* enforce numeric properties of element */
85 els[i].onkeypress = (function(e) {
86 return function(ev) {
87 ev = ev || window.event;
88 var key = ev.keyCode || ev.which,
89 keyst = String.fromCharCode(ev.charCode || ev.keyCode),
90 ente = enterActions[e.name||e.id];
91
92 if (ev.ctrlKey || ev.metaKey) {
93 return;
94 }
95
96 (key == 13) && ente && ente();
97
98 if (hasClass(e, 'numeric') && ev.charCode && !keyst.match(/[0-9]/)) {
99 stopPropagation(ev); return false;
100 } else if (hasClass(e, 'hex') && ev.charCode && !keyst.match(/[0-9a-fA-F ]/)) {
101 stopPropagation(ev); return false;
102 }
103 };
104 })(els[i]);
105
106 if (els[i].type == 'radio') {
107 if (this[name] === undefined) {
108 this[name] = new radioGroup(name);
109 this._elNames.push(name);
110 }
111 } else {
112 /* code to get the value of an element */
113 this[name] = new formElement(els[i]);
114 this._elNames.push(name);
115 }
116 }
117}
118
119formHandler.prototype = {
120 get:function() {

Callers

nothing calls this directly

Calls 2

hasClassFunction · 0.85
stopPropagationFunction · 0.85

Tested by

no test coverage detected