npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

outperform

v1.1.10

Published

Form generator using plain javascript

Downloads

19

Readme

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 id DOM-namespace by using form-relative name references 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]
  • name Is the name attribute for this input field.
  • type Is the type attribute for this input field. All browser native types are supported. Special values are select or textarea, which generate corresponding input fields.
  • description Should be the human readable description of this field.
  • options Is 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:
    • template Defaults to:
       <label><span></span><input /></label>
      And can be specified per input field if so desired.
    • labelsel Defaults to: span And identifies the first element whose content shall be replaced by the human readable form of the description of the input field.
    • persist A boolean which determines if this field's content will persist accross browser reloads. Defaults to true for all types except password.
    • validate Can 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.
    • node Can 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.
    • list An array of values for a select, checkbox or radio element. Every entry needs to satisfy the following rules:
      • select values should contain one or two strings (separate value is optional) followed by an optional option object per row.
      • checkbox and radio values 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:

  • form A reference to the current form node.
  • fielddescription The description of an input field.
  • fields An array of fielddescription fields.

Exposed API-list:

  • Outperform.create(formtag, attributes, fields) Creates an HTML element using the tag in the string formtag (usually "form", unless you deviate from HTML5) adorned by the attributes listed in the attributes object. The form is filled using the fielddescriptions in the fields array. 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 in values.
  • Outperform.obj2formdata(values) Returns the equivalent formData object.
  • Outperform.field(form, fielddescription) Return a single node that is equivalent to the provided fielddescription (used internally by Outperform.create()). This method can be used to construct completely custom form elements, by inserting them manually into the form created by Outperform.create().

References

Card-carrying member of the zerodeps movement.