forked from BasicPrimitives/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextBox.js
More file actions
48 lines (44 loc) · 1.36 KB
/
TextBox.js
File metadata and controls
48 lines (44 loc) · 1.36 KB
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
import { ControlType } from './enums';
export function TextBoxConfig(id, defaultItem, caption, valueType, onUpdate) {
this.controlType = ControlType.TextBox;
this.id = id;
this.defaultItem = defaultItem;
this.caption = caption;
this.valueType = valueType;
this.onUpdate = onUpdate;
};
export function TextBoxRender() {
this.render = function (config, namespace, defaultValue) {
var controlBody = ["span",
["br"],
["label",
{
"title": config.id,
"for": namespace + config.id
},
config.caption
],
'\xa0',
["input",
{
"type": "text",
"name=": namespace + config.id,
"class": ["text", "ui-widget-content", "ui-corner-all"],
"value": (defaultValue != null ? defaultValue : ""),
"$": function (element) {
element.addEventListener('change', function () {
config.onUpdate(element, config);
});
}
}
]
];
return controlBody;
};
this.getValue = function (item, namespace, formatters) {
var formatter = formatters[item.valueType],
element = document.getElementsByName(namespace + item.id)[0],
result = formatter(element.value);
return result;
};
};