<link rel="stylesheet" type="text/css" href="../../codebase/skins/dhtmlxform_dhx_skyblue.css">
<script src="../../codebase/dhtmlxcommon.js"></script>
<script src="../../codebase/dhtmlxform.js"></script>
<script>var myForm,
formData;
function doOnLoad() {
formData = [{
type: "checkbox",
label: "Check me",
position: "label-right",
list: [{
type: "myItem",
name: "test",
my_text: "This is custom item",
list: [{
type: "radio",
name: "r0",
label: "Select me!",
position: "label-right",
checked: true
}, {
type: "radio",
name: "r0",
label: "No, better select me!",
position: "label-right"
}]
}]
}];
myForm = new dhtmlXForm("myForm", formData);
myForm.setItemValue("test", "item value");
myForm.setItemText("test", "new item text");
myForm.setBoldTextForMyItem("test", "new item text 2");
}
dhtmlXForm.prototype.items.myItem = {
render: function(item, data) {
item._type = "myItem";
item.appendChild(document.createElement("DIV"));
item.lastChild.innerHTML = data.my_text;
this._custom_inner_func(item);
return this;
},
destruct: function(item) {
this._custom_inner_func2(item);
item.innerHTML = "";
},
enable: function(item) {
item.lastChild.style.color = "black";
item._is_enabled = true;
},
disable: function(item) {
item.lastChild.style.color = "gray";
item._is_enabled = false;
},
_custom_inner_func: function(item) {
item.lastChild.onclick = function() {
if (this.parentNode._is_enabled)
alert("Hello!")
}
},
_custom_inner_func2: function(item) {
item.lastChild.onclick = null;
},
setText: function(item, text) {
item.lastChild.innerHTML = text;
item.callEvent("onTextChanged", [item._idd, text]);
},
setBoldText: function(item, text) {
item.lastChild.innerHTML = "<b>" + text + "</b>";
item.callEvent("onTextChanged", [item._idd, text, true]);
},
setValue: function(item, val) {
item._value = val;
},
getValue: function(item) {
return item._value;
}
};
dhtmlXForm.prototype.setBoldTextForMyItem = function(name, text) {
this.doWithItem(name, "setBoldText", text);
};
dhtmlXForm.prototype.setFormData_myItem = function(name, value) {
return this.doWithItem(name, "setValue", value);
};
dhtmlXForm.prototype.getFormData_myItem = function(name) {
return this.doWithItem(name, "getValue");
};
</script>
<div id="myForm" style="height:150px;"></div>