# @deleteagency/forms

> [Live Demo](https://delete-agency.github.io/forms/)

Latest version **1.0.0** (published 2019-11-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @deleteagency/forms
pnpm add @deleteagency/forms
yarn add @deleteagency/forms
bun add @deleteagency/forms
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-11-25 |
| First published | 2019-09-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 982.7 KB |
| Known vulnerabilities | 0 (+25 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | sleepyhead |

## Links

- npm: https://www.npmjs.com/package/@deleteagency/forms
- Repository: https://github.com/Delete-Agency/forms
- Issues: https://github.com/Delete-Agency/forms/issues
- npm.io page: https://npm.io/package/@deleteagency/forms

## Dependencies (4)

- [axios](https://npm.io/package/axios.md) ^0.19.0
- [jquery](https://npm.io/package/jquery.md) ^3.4.1
- [parsleyjs](https://npm.io/package/parsleyjs.md) ^2.9.1
- [@deleteagency/dom-helper](https://npm.io/package/@deleteagency/dom-helper.md) ^3.0.0

## Recent versions

- 1.0.0 (latest) — 2019-11-25
- 2.0.0-0 (next) — 2019-12-12
- 1.0.0-4 — 2019-11-08
- 1.0.0-3 — 2019-11-08
- 1.0.0-2 — 2019-11-08
- 1.0.0-1 — 2019-10-29
- 1.0.0-0 — 2019-10-29
- 0.0.1 — 2019-09-30

## README

# Forms

[Live Demo](https://delete-agency.github.io/forms/)

## Motivation

TODO


## Installation

Use the package manager [npm](https://docs.npmjs.com/about-npm/) for installation.

```
$ npm install @deleteagency/forms
```

## Usage

```js
import {Form} from  '@deleteagency/forms';

let formElement1 = document.getElementById('form1');

// Extending with options example
const form1 = new Form(formElement1, {
    submitElement: formElement1.querySelector('button[type="submit"]'),
    errorsSummary: formElement1.querySelector('[data-errors-summary]'),
    onSuccessfulSubmit: (response) => {
        console.log(response);
    },
    onFailedSubmit: (error) => {
        console.error(error);
    },
    errorsSummaryTemplate: (errors) => {
        return `<div class="alert alert-danger" role="alert">${errors.map(error => `<div>${error}</div>`).join()}</div>`;
    },
    parsley: {
        errorClass: 'is-invalid',
        successClass: 'is-valid',
        errorsWrapper: '<div class="invalid-feedback" aria-live="assertive"></div>',
        errorTemplate: '<div></div>',
    },
});

// Extending with inheritance example
class BaseForm extends Form {
    constructor(el, options) {
        options = {
            ...options,
            submitElement: el.querySelector('button[type="submit"]'),
            errorsSummary: el.querySelector('[data-errors-summary]'),
            parsley: {
                errorClass: 'is-invalid',
                successClass: 'is-valid',
                errorsWrapper: '<div class="invalid-feedback" aria-live="assertive"></div>',
                errorTemplate: '<div></div>',
            },
        };
        super(el, options);
    }

    onSuccessfulSubmit(response) {
        console.log(response);
    }

    onFailedSubmit(error) {
        console.error(error);
    }

    errorsSummaryTemplate(errors) {
        return `<div class="alert alert-danger" role="alert">${errors.map(error => `<div>${error}</div>`).join()}</div>`;
    }
}

let formElement2 = document.getElementById('form2');
const form2 = new BaseForm(formElement2);
```

## API

### new Form(element, options = {})

#### element

*Required*<br>
Type: `HTMLFormElement`

#### options

*Optional*<br>
Type: `Object`

## Options

### async

Type: `boolean`<br>
Default: `true`

Should form be submitted via XHR (axios) or natively.

### errorsSummaryElement

Type: `HTMLElement`<br>
Default: `null`

todo

### submitElement

Type: `HTMLElement`<br>
Default: `null`

todo

### axiosInstance

Type: `Axios`<br>
Default: `require('axios')`

todo

### formControlAttribute

Type: `string`<br>
Default: `data-form-control`

todo

### formControlAttributeCustom

Type: `string`<br>
Default: `data-form-control-name`

todo

### validateAlwaysAttribute

Type: `string`<br>
Default: `data-validate-always`

todo

### parsley

Type: `Parsley settings`<br>
Default: `{
    errorClass: 'is-invalid',
    successClass: 'is-valid',
    errorsWrapper: '<ul aria-live="assertive"></ul>',
    errorTemplate: '<li></li>',
}`

todo

### extractValidationErrors (inheritable)

Type: `Function`<br>

todo

### errorsSummaryTemplate (inheritable)

Type: `Function`<br>

todo

### beforeSubmitPromise (inheritable)

Type: `Function`<br>

tod

### onBeforeSubmit (inheritable)

Type: `Function`<br>

todo

### onAfterSubmit (inheritable)

Type: `Function`<br>

todo

### onSuccessfulSubmit (inheritable)

Type: `Function`<br>

todo

### onFailedSubmit (inheritable)

Type: `Function`<br>

todo

### onError (inheritable)

Type: `Function`<br>

todo

## License
[MIT](https://choosealicense.com/licenses/mit/)

---
_Source: https://npm.io/package/@deleteagency/forms · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
