# FormaJS v1.0.0

Quickly and easily create dynamic and interactive forms with a better end-user experience.

FormaJS lets you customize and style your forms in numerous different ways and at the same time gives you the base and structure that will save you time and effort while building form prototypes.

**Latest Release:** v1.0.0 – the first stable release.

There are few different ways to use and load up the script and stylesheet templates. Take a look at main website for complete [documentation](https://formajs.krasenslavov.com/index.html) with usage, features and [examples](https://formajs.krasenslavov.com/examples/index.html).

## What's New in v1.0.0

- First stable release, installable from npm (`aformajs`) with ESM, CommonJS and browser builds plus TypeScript types
- Several forms on one page now work independently
- Safer rendering: typed values and labels are never injected as HTML
- Better accessibility: `aria-invalid`, `aria-describedby`, live error messages, valid markup, no keyboard trap
- Tab only intercepted when `tab: true`; Tab on the last row moves on to the submit button
- Test suite and CI

For detailed changes, see [CHANGELOG.md](CHANGELOG.md).

## Install

```bash
npm i aformajs
```

```js
import forma from 'aformajs';
import 'aformajs/css/forma.css'; // or forma-base, forma-barebone, forma-boilerplate

forma({container: '.forma', auto: true});
```

CommonJS (`require('aformajs')`) and a browser build (`dist/js/forma.min.js`, exposing `window.forma`) are included. It is also on jsDelivr/unpkg: `https://cdn.jsdelivr.net/npm/aformajs@1.0.0/dist/js/forma.min.js`.

## Options

| Option | Default | Description |
|---|---|---|
| `container` | `'.forma'` | CSS selector of the form |
| `tab` | `false` | Tab moves between rows, one open at a time |
| `show` | `false` | Show all rows |
| `auto` | `false` | Generate placeholders and descriptions from the labels |
| `manual` | `false` | Add a +/- toggle to each row |
| `submit` | `false` | Disable the submit button until the form is valid |
| `prefix` / `suffix` | `'Enter'` / `'...'` | Text around the label in auto mode |
| `support` | `[]` | Extra supported elements, e.g. `'input[type="tel"]'` |
| `struct` | `{}` | `{title, abbr, wrapper: 'div' \| 'section' \| 'ul>li'}` |
| `integrate` | `''` | `'forma'` or `'bootstrap'` (Bootstrap 4) |

On touch-first devices (`pointer: coarse`) all rows are shown and `tab`/`manual` are ignored.

## Quick Start

Download the master (or the [latest release](https://github.com/krasenslavov/formajs/releases)). Minified version of the script with all the stylesheet templates can be found under `/dist`.

1. Copy-paste the `<link>` into your HTML document `<head>` and add the path to the startup stylesheet template you plan to use (found inside the `/dist/css` folder).

```html
<link href="path/to/css/forma.css" rel="stylesheet" />
```

2. Build your form anywhere inside the `<body>` of you document. The example below shows up the minimum required attributes for your form elements.

```html
<form class="forma">
  <input data-label="Email Address" type="email" name="email-address" />
  <input data-label="First Name" type="text" name="first-name" />
  <input data-label="Last Name" type="text" name="last-name" />
  <textarea data-label="Message" rows="5" name="message"></textarea>
  <button type="submit">Send</button>
</form>
```

**All you need to add are the form elements; the actual form structure will be auto-generated by the script.**

3. Place the following `<script>`'s near the end of your document, right before the closing `</body>` tag. And you are all set up.

```html
<script src="path/to/js/forma.min.js"></script>
<script>forma();</script>
```

Visit our main [website](https://formajs.krasenslavov.com/) to learn more about customization, client-side validations, custom settings and a whole lot more.

## [Documentation](https://formajs.krasenslavov.com/)

* [Basic Usage](https://formajs.krasenslavov.com/index.html)
* [Installation](https://formajs.krasenslavov.com/index.html#installation)
* [Form Structure](https://formajs.krasenslavov.com/index.html#structure)
* [Custom Settings](https://formajs.krasenslavov.com/index.html#settings)
* [Customization and Styling](https://formajs.krasenslavov.com/index.html#styling)
* [Client-side Validation](https://formajs.krasenslavov.com/index.html#validation)
* [CSS](https://formajs.krasenslavov.com/css/index.html)
* [SASS/SCSS](https://formajs.krasenslavov.com/scss.html)
* [NPM](https://formajs.krasenslavov.com/npm.html)
* [Examples](https://formajs.krasenslavov.com/examples/index.html)
* [Sandbox](https://formajs.krasenslavov.com/sandbox.html)

## Security

The library ships with zero runtime dependencies. See [SECURITY.md](SECURITY.md) to report a vulnerability.

## [Contribute](https://formajs.krasenslavov.com/index.html#contribute)

Found a bug or want to propose some improvements or fixes to the documentation? Visit our [website](https://formajs.krasenslavov.com/index.html#contribute) and see all the different ways you can contribute to this project.

## [License](https://formajs.krasenslavov.com/index.html#license)

(c) Krasen Slavov | Code released under the [MIT License](https://opensource.org/licenses/MIT).

## Development

```bash
npm install
npm run build   # dist/js (esm, cjs, iife) + dist/css + docs copy
npm test
```
