An open API service indexing awesome lists of open source software.

https://github.com/nju33/efo

Good form? To make
https://github.com/nju33/efo

form input library pure-javascript textarea

Last synced: 5 months ago
JSON representation

Good form? To make

Awesome Lists containing this project

README

          

# Efo

Good form? To make

![screenshot](https://github.com/nju33/efo/raw/master/images/screenshot.gif?raw=true)

## Install or Download

```sh
yarn add efo
npm i -S efo
```

Or access to [releases page](https://github.com/nju33/efo/releases).
Then, download the latest version.

## Usage

First, if you read as a separate file

```html

```

Several new attributes will appear.

- `data-efo-name`
This will be the name of the input part.
This can be substituted for name originally in ``. This is used when you want to add a name to more than one ``.
- `data-efo-error-class`
When an error occurs in the validation of the input form, add `.efo-error`. Also, when solving it add `.efo-resolved`.
- `data-efo-error-message`
Inserts an error message in `innerText` of the element set on error.
- `data-efo-set-default-height`
In error, specify the height of `clientHeight` in style with the element with that value. This can be used to apply the `transition` of CSS when `.efo-error` is gone and the height returns.

```html


Name






Adress


-






```

`efo.validate` checks all elements. Returns a `Boolean`.

```js
const efo = new Efo({
target: document.getElementById('form'),
data: {
// When solving the error, keep `.efo-error` 300ms
leaveTransitionSec: 300,
// key: string
// Name `data-efo-name` or` name`
//
// value: (el1: HTMLElement, el2: HTMLElement, ...): [bool, string]
// Elements with that name are all passed.
// The return value is
// - Pass validation?
// - Error message
tests: {
name(el) {
if (el.value.length >= 3) {
return [true];
}
return [false, 'Three or more characters are required'];
},
address(el1, el2) {
const val = el1.value + '-' + el2.value;
const re = /^\d{3}-\d{4}/;
if (re.test(val)) {
return [true];
}
return [false, 'Invalid address'];
},
}
}
});

document.getElementById('submit-button').addEventListener('click', ev => {
ev.preventDefault();

// `Scroll` means to scroll to the very first error element on error.
const bool = efo.validate({scroll: true});

if (bool) {
form.submit();
}
});
```

### Example

- `test/fixtures/index.js`
- `example/webpack/index.js`

## LICENSE

The MIT License (MIT)

Copyright (c) 2017 nju33