outperform v1.1.10
Outperform is a form generator written in plain Javascript with zero dependencies. It supports and augments browser native form validation and offers automatic persistence of half-filled forms across page reloads while integrating with any and all web frameworks.
Requirements
It runs inside any webbrowser environment (starting at IE11 and up).
Features
- Zero dependencies.
- Less filling (unminified but gzipped: <2KB).
- Native browser form validation support for all HTML5+ input types.
- Custom validation seemlessly integrated.
- Compact form description format.
- Customisable nested HTML templates that allow seemless integration with any web framework (e.g. Bootstrap).
- Automatic and consistent persistence of forms across page reloads in all browsers.
- Convenience functions to easily retrieve and (pre)set all form data using javascript objects (ideal for custom processing of form submissions).
- Does not invade or mess up your
idDOM-namespace by using form-relativenamereferences internally exclusively.
Basic usage
var fields = [
[ "houseno", "number", "This is the description", {min:1, max:999}],
[ "foo", "text", "This is the description",
{validate:function(flds) {
if (flds.foo.value != flds.foo2.value)
return "Mismatch between foo en foo2 fields";
}],
[ "foo2", "password", "This is the description"],
[ "bar", "select", "This is the description",
{list:
["one",
["two", {class:"bright"}],
["three", "Three choices"],
"four",
["five", "Five", {style:"display:none;"}],
]
}
],
[ "bar2", "checkbox", "This is the description",
{list:
["one",
["two", {class:"bright", value:"2"}],
["Three choices"],
"four",
["Five", {style:"display:none;", value:"5"}],
],
template:"<fieldset><legend></legend><input /></fieldset>",
labelsel:"legend",
}
],
];
var form = Outperform.create("form", {id:"hello"}, fields);
document.body.appendChild(form);
// on submit:
if (form.reportValidity()) {
console.log(JSON.stringify(Outperform.getfields(form)));
Outperform.clearpersist(form);
}Reference documentation
Fielddescriptions are an array of values:
[ name, type, description, options]nameIs the name attribute for this input field.typeIs the type attribute for this input field. All browser native types are supported. Special values areselectortextarea, which generate corresponding input fields.descriptionShould be the human readable description of this field.optionsIs an optional field that can contain an object. All values in this object will become attributes on the input field. Exception to this rule are a few special attributes:templateDefaults to:
And can be specified per input field if so desired.<label><span></span><input /></label>labelselDefaults to:spanAnd identifies the first element whose content shall be replaced by the human readable form of the description of the input field.persistA boolean which determines if this field's content will persist accross browser reloads. Defaults totruefor all types exceptpassword.validateCan be defined to a function which performs custom validation checks. The function receives a single parameter which can be indexed by the name of an input element to reference the input element nodes.nodeCan be defined to a function which is run once right after the template has been fully instantiated. The first parameter is a reference to the input element node itself, and the second parameter is a reference to the top element node in this templaterow.listAn array of values for aselect,checkboxorradioelement. Every entry needs to satisfy the following rules:selectvalues should contain one or two strings (separate value is optional) followed by an optional option object per row.checkboxandradiovalues should contain a single string, or a single string followed by an option object, or a full fielddescription array (the latter can be used to recursively nest arbitrarily complex HTML structures in the form).
API
Specified parameters:
formA reference to the current form node.fielddescriptionThe description of an input field.fieldsAn array offielddescriptionfields.
Exposed API-list:
Outperform.create(formtag, attributes, fields)Creates an HTML element using the tag in the stringformtag(usually"form", unless you deviate from HTML5) adorned by the attributes listed in theattributesobject. The form is filled using the fielddescriptions in thefieldsarray. It returns a reference to the form node which should normally be inserted into the DOM.Outperform.clearpersist(form)Clears the persistent storage used to store half-filled form data. Intended to be used right after submitting the form successfully.Outperform.getvalues(form)Returns an object containing all entered values in the form.Outperform.setvalues(form, values)(Pre)sets all values in the form using the object invalues.Outperform.obj2formdata(values)Returns the equivalentformDataobject.Outperform.field(form, fielddescription)Return a single node that is equivalent to the providedfielddescription(used internally byOutperform.create()). This method can be used to construct completely custom form elements, by inserting them manually into the form created byOutperform.create().
References
Card-carrying member of the zerodeps movement.
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago