Dynaform is a project mainly written in JavaScript, it's free.
A jQuery plugin to dynamically create forms
Plugin to dynamically create forms. The plugin has been originally designed to run on the server (in Node.js, using express-jsdom), but of course works perfectly well in the browser, too.
$('#elem').dynaform(data, setup)
Creates form elements as specified by the setup function and appends them to the matched element.
$('#elem').dynaform(data, function() {
this.text('name')
.text('email', { required: true })
.list('links', function() {
this.text();
});
});
The this object has a method for each available widget, i.e. the built-in widgets as well as the custom ones.
All these methods take up to three arguments (depending on their type and context):
The following options can be used for all widgets:
$.dynaform.naming.label()
.A simple textfield. Currently only the common options are supported.
A simple textfield. Currently only the common options are supported.
A jQuery UI datepicker. All options are passed verbatim to the jQuery UI widget.
A simple ckeckbox. Options:
A nested form. Example:
this.nested('address', function() {
this.text('street')
.text('city');
});
A list editor. Options:
You can register your own widgets via $.dynaform.register(builders)
. Here's an example of a simple password field:
$.dynaform.register({
password: function(options) {
return $('<input type="password">')
.attr('name', options.name)
.attr('value', options.value);
}
});
When a builder method is invoked, an options object is passed with the following properties:
You may change the way how parameter names, ids, or labels are created, by overwriting any of the $.dynaform.naming
functions.
If you register a widget with a name that already exists, the original implementation is passed to your builder-function as second argument. Here's an example that support for the rows
attribute to the default textarea implementation:
$.dynaform.register({
textarea: function(options, textarea) {
return textarea(options).attr('rows', options.rows || 5);
}
});