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

formist

v0.3.0

Published

A library to publish, consume and validate HTML5 forms.

Downloads

297

Readme

formist

Build Status Coverage Status

Formist is a node.js forms library.

The key difference between Formist and other node.js forms libraries, is that its DSL more closely matches that of HTML form tags, providing much more flexibility. No widgets.

It was designed to be:

  • highly flexible
  • easy to manipulate output for styling (using themes)

To do

It is still in early stages of development, and has to date been focused on output generation. The following needs to make its way into the library:

  • form binding
  • server-side validation handling
  • error handling
  • form + error rendering

Installing

npm install formist --save

Requiring formist

var formist = require('formist');

Examples

The best way to learn is by example. There are a number of examples in the formist-example repository.

Creating forms

The following breaks down Formist forms technology.

Form

A Form is a standard HTML form. A Form can contain multiple:

  • Fieldset
  • Field
  • Fieldgroup

To create a form

var form = new formist.Form(options, elements);

formist.Form will take an options object (options), with the following:

  • renderTag, Boolean: set this to false, to render the form without <form></form> tags. Defaults to true.
  • theme, Object: a key-function object defining theming overrides. This is optional.
  • attributes, Object: a key-value object defining any HTML tags (including action and method). This is optional.

formist.Form will take an array of Fieldset, Field or Fieldgroup objects (elements).

To add form elements

form.add(element);

formist.Form.add will take a Fieldset, Field, or Fieldgroup.

Fieldset

A Fieldset represents a standard HTML fieldset. A Fieldset can contain multiple:

  • Fieldgroup
  • Field

To create a fieldset

var fieldset = form.add(formist.Fieldset([options, elements]));

formist.Fieldset will optionally take an options object (options), with the following:

  • legend, String: a string value for the HTML legend tag. This is optional.
  • theme, Object: a key-function object defining theming overrides. This is optional.
  • attributes, Object: a key-value object defining any HTML tags. This is optional.

formist.Fieldset will take an Array, elements of Fieldset, Field or Fieldgroup objects.

To add form elements

fieldset.add(element);

formist.Form.add will take a Field, or Fieldgroup.

Field

A field presents a label, and HTML form control (i.e. input, select, button, textarea). A field can not contain anything.

To create a field

form.add(formist.Field(tag, options));

formist.Field will take a String, tag representing the name of the HTML tag to produce (i.e. input, select, button, textarea).

formist.Field will take an Object, options, with the following:

  • label, Object: an object with a label key, and an attributes object representing key-value attributes to apply to the label tag. For brevity, this can be a string, if non attributes are required. This is optional.
  • helpText, Object: an object with a text key, tag key (defaulting to 'small), and an attributes object representing key-value attributes to apply to the small tag. For brevity, this can be a string, if no attributes or tag changes are required. This is optional.
  • theme, Object: a key-function object defining theming overrides. This is optional.
  • attributes, Object: a key-value object defining any HTML tags. This is optional.

Control

A control represents a HTML form control (i.e. input, select, button, textarea). You don't define controls specifically, you can only wrap them.

Fieldgroup

A fieldgroup represents a group of fields (i.e. Field). A field group can be passed multiple:

  • Field

To create a fieldgroup

form.add(formist.Fieldgroup(options, elements));

formist.Fieldgroup will take an Object, options, with the following:

  • label, Object: an object with a label key, and an attributes object representing key-value attributes to apply to the label tag. For brevity, this can be a string, if non attributes are required. This is optional.
  • helpText, Object: an object with a text key, tag key (defaulting to 'small), and an attributes object representing key-value attributes to apply to the small tag. For brevity, this can be a string, if no attributes or tag changes are required. This is optional.
  • theme, Object: a key-function object defining theming overrides. This is optional.
  • attributes, Object: a key-value object defining any HTML tags. This is optional.

formist.Fieldgroup will take an Array, elements of Field.

Theming

Formist has advanced support for theming. To define a theme, you can pass a theme object, with the following functions and signatures.

theme: {
	form: function (content, form) {
	},
	fieldset: function (content, fieldset) {
	},
	fieldgroup: {
		group: function (label, content, fieldgroup) {
		},
		fields: function (content, fields) {
		},
		field: function (label, content, field) {
		}
	},
	field: function (label, content, field) {
	},
	control: function (content) {
	}
}