jQuery.dForm 1.0.1 example
This is a simple example for jQuery.dForm
by mkdizajn
HTML
<script src="http://daffl.github.io/jquery.dform/release/jquery.dform-1.1.0.js"></script>
<form id="myform"></form>
JavaScript
$.dform.addType("string", function(options) {
// Return a new button element that has all options that
// don't have a registered subscriber as attributes
return $("<input>").dform('attr', options);
});
$.dform.addType("boolean", function(options) {
// Return a new button element that has all options that
// don't have a registered subscriber as attributes
return $("<input type=\"checkbox\" />").val(options.value);
});
$.dform.subscribe("name", function(options, type) {
if(type === "string") {
var ops = {};
if(typeof (options) === "string") {
ops.html = options;
} else {
$.extend(ops, options);
}
ops.type = "label";
if(this.attr("id")) {
ops.for = this.attr("id");
}
var label = $($.dform.createElement(ops));
if(type === "checkbox" || type === "radio") {
this.parent().append($(label));
} else {
label.insertBefore(this);
}
label.dform('append', ops);
}
});
// Generate a form
$("#myform").dform({
"action": "index.html",
"method": "get",
"html": [
{
"scope": "global",
"name": "desdfa",
"value": "Looks very interesting!",
"type": "string"
},
{
"scope": "global",
"name": "notEnoughInformation",
"value": false,
"type": "boolean"
},
{
"scope": "global",
"name": "initiator",
"value": "kermit",
"type": "string"
},
{
"name": "birthdate",
"type": "date",
"value": "2014-06-24T07:00:00Z",
"scope": "global"
},
{
"type": "submit",
"value": "Login"
}
]
});